a

Dependencies:   EthernetNetIf HTTPClient mbed

Fork of TwitterExample by Donatien Garnier

Committer:
kuwaeyoshi
Date:
Fri Aug 24 04:23:06 2018 +0000
Revision:
4:3888766d37fe
Parent:
2:2a9775a81062
a

Who changed what in which revision?

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