![](/media/cache/profiles/5f14615696649541a025d3d0f8e0447f.jpg.50x50_q85.jpg)
Dependencies: EthernetNetIf mbed HTTPClient_ToBeRemoved
TwitterExample.cpp@0:16fbd40f350f, 2012-04-28 (annotated)
- Committer:
- jksoft
- Date:
- Sat Apr 28 07:21:13 2012 +0000
- Revision:
- 0:16fbd40f350f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:16fbd40f350f | 1 | /* |
jksoft | 0:16fbd40f350f | 2 | Update: 21-06-2010 |
jksoft | 0:16fbd40f350f | 3 | The basic authentication service for twitter is going down at the end of the week. |
jksoft | 0:16fbd40f350f | 4 | To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy. |
jksoft | 0:16fbd40f350f | 5 | Simply visit the website to setup your twitter account for this API. |
jksoft | 0:16fbd40f350f | 6 | See: http://www.supertweet.net/about/documentation |
jksoft | 0:16fbd40f350f | 7 | */ |
jksoft | 0:16fbd40f350f | 8 | |
jksoft | 0:16fbd40f350f | 9 | #include "mbed.h" |
jksoft | 0:16fbd40f350f | 10 | #include "EthernetNetIf.h" |
jksoft | 0:16fbd40f350f | 11 | #include "HTTPClient.h" |
jksoft | 0:16fbd40f350f | 12 | |
jksoft | 0:16fbd40f350f | 13 | EthernetNetIf eth; |
jksoft | 0:16fbd40f350f | 14 | |
jksoft | 0:16fbd40f350f | 15 | int main() { |
jksoft | 0:16fbd40f350f | 16 | |
jksoft | 0:16fbd40f350f | 17 | printf("Init\n"); |
jksoft | 0:16fbd40f350f | 18 | |
jksoft | 0:16fbd40f350f | 19 | printf("\r\nSetting up...\r\n"); |
jksoft | 0:16fbd40f350f | 20 | EthernetErr ethErr = eth.setup(); |
jksoft | 0:16fbd40f350f | 21 | if(ethErr) |
jksoft | 0:16fbd40f350f | 22 | { |
jksoft | 0:16fbd40f350f | 23 | printf("Error %d in setup.\n", ethErr); |
jksoft | 0:16fbd40f350f | 24 | return -1; |
jksoft | 0:16fbd40f350f | 25 | } |
jksoft | 0:16fbd40f350f | 26 | printf("\r\nSetup OK\r\n"); |
jksoft | 0:16fbd40f350f | 27 | |
jksoft | 0:16fbd40f350f | 28 | HTTPClient twitter; |
jksoft | 0:16fbd40f350f | 29 | |
jksoft | 0:16fbd40f350f | 30 | HTTPMap msg; |
jksoft | 0:16fbd40f350f | 31 | msg["status"] = "I am tweeting from my mbed!"; //A good example of Key/Value pair use with Web APIs |
jksoft | 0:16fbd40f350f | 32 | |
jksoft | 0:16fbd40f350f | 33 | twitter.basicAuth("", ""); //We use basic authentication, replace with you account's parameters |
jksoft | 0:16fbd40f350f | 34 | |
jksoft | 0:16fbd40f350f | 35 | //No need to retieve data sent back by the server |
jksoft | 0:16fbd40f350f | 36 | HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); |
jksoft | 0:16fbd40f350f | 37 | if( r == HTTP_OK ) |
jksoft | 0:16fbd40f350f | 38 | { |
jksoft | 0:16fbd40f350f | 39 | printf("Tweet sent with success!\n"); |
jksoft | 0:16fbd40f350f | 40 | } |
jksoft | 0:16fbd40f350f | 41 | else |
jksoft | 0:16fbd40f350f | 42 | { |
jksoft | 0:16fbd40f350f | 43 | printf("Problem during tweeting, return code %d\n", r); |
jksoft | 0:16fbd40f350f | 44 | } |
jksoft | 0:16fbd40f350f | 45 | |
jksoft | 0:16fbd40f350f | 46 | return 0; |
jksoft | 0:16fbd40f350f | 47 | |
jksoft | 0:16fbd40f350f | 48 | } |