Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TwitterExample.cpp
00001 /* 00002 Update: 21-06-2010 00003 The basic authentication service for twitter is going down at the end of the week. 00004 To continue using that program, the code has been updated to use http://supertweet.net which acts as an API proxy. 00005 Simply visit the website to setup your twitter account for this API. 00006 See: http://www.supertweet.net/about/documentation 00007 */ 00008 00009 #include "mbed.h" 00010 #include "EthernetNetIf.h" 00011 #include "HTTPClient.h" 00012 00013 EthernetNetIf eth; 00014 00015 int main() { 00016 00017 printf("Init\n"); 00018 00019 printf("\r\nSetting up...\r\n"); 00020 EthernetErr ethErr = eth.setup(); 00021 if(ethErr) 00022 { 00023 printf("Error %d in setup.\n", ethErr); 00024 return -1; 00025 } 00026 printf("\r\nSetup OK\r\n"); 00027 00028 HTTPClient twitter; 00029 00030 HTTPMap msg; 00031 //msg["status"] = "I am tweeting from my mbed!"; //A good example of Key/Value pair use with Web APIs 00032 LocalFileSystem local("local"); 00033 char s[256]; 00034 FILE *fp; 00035 00036 printf("\r\nreading a message file.\r\n"); 00037 00038 if(NULL == (fp = fopen("/local/tweet.txt","r")) ) { 00039 printf("\r\nError: The message file cannot be accessed\r\n"); 00040 return -1; 00041 } 00042 00043 fgets(s,256,fp); 00044 fclose(fp); 00045 00046 msg["status"] = s; 00047 00048 twitter.basicAuth("user", "pass"); //We use basic authentication, replace with you account's parameters 00049 00050 //No need to retieve data sent back by the server 00051 HTTPResult r = twitter.post("http://api.supertweet.net/1/statuses/update.xml", msg, NULL); 00052 if( r == HTTP_OK ) 00053 { 00054 printf("Tweet sent with success!\n"); 00055 } 00056 else 00057 { 00058 printf("Problem during tweeting, return code %d\n", r); 00059 } 00060 00061 return 0; 00062 00063 }
Generated on Thu Aug 25 2022 19:33:28 by
1.7.2