TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

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