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