Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html
Dependencies: mbed HTTPClient NTPClient_NetServices EthernetNetIf
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPClient.h" 00004 #include "NTPClient.h" 00005 00006 #include "oauth.h" 00007 00008 EthernetNetIf eth(IpAddr(192,168,0,100), //IP Address 00009 IpAddr(255,255,255,0), //Network Mask 00010 IpAddr(192,168,0,1), //Gateway 00011 IpAddr(192,168,0,1) //DNS 00012 ); 00013 NTPClient ntp; 00014 HTTPClient http; 00015 00016 DigitalOut led(LED1); 00017 00018 // IMPORTANT: please change the following keys for your application. 00019 00020 static char const consumer_key[] = "AAAAAAAAAAAAAAAAAAAAAA"; 00021 static char const consumer_secret[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 00022 00023 static char const token_key[] = "00000000-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 00024 static char const token_secret[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 00025 00026 // get current time and set to system clock 00027 00028 void reset_time() 00029 { 00030 Host server(IpAddr(), 123, "ntp.jst.mfeed.ad.jp"); 00031 ntp.setTime(server); 00032 } 00033 00034 // post message to Twitter 00035 00036 void tweet(char const *message) 00037 { 00038 00039 std::string uri = "http://api.twitter.com/1/statuses/update.xml"; 00040 uri += "?status="; 00041 uri += oauth_url_escape(message); 00042 00043 std::string req_url; 00044 std::string postarg; 00045 00046 req_url = oauth_sign_url2(uri.c_str(), &postarg, OA_HMAC, 0, consumer_key, consumer_secret, token_key, token_secret); 00047 oauth_http_post(req_url.c_str(), postarg.c_str()); 00048 } 00049 00050 // 00051 00052 int main() 00053 { 00054 eth.setup(); 00055 00056 reset_time(); 00057 00058 tweet("Hello, world"); 00059 00060 while(1) { 00061 led = 1; 00062 wait(0.5); 00063 led = 0; 00064 wait(0.5); 00065 } 00066 }
Generated on Sun Jul 17 2022 13:32:19 by 1.7.2