Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html

Dependencies:   mbed HTTPClient NTPClient_NetServices EthernetNetIf

Committer:
soramimi
Date:
Thu Nov 15 00:51:45 2012 +0000
Revision:
1:c3f74457cad4
Parent:
0:7ddb56bfde0c
Twitter API address changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soramimi0:7ddb56bfde0c 1#include "mbed.h"
soramimi0:7ddb56bfde0c 2#include "EthernetNetIf.h"
soramimi0:7ddb56bfde0c 3#include "HTTPClient.h"
soramimi0:7ddb56bfde0c 4#include "NTPClient.h"
soramimi0:7ddb56bfde0c 5
soramimi0:7ddb56bfde0c 6#include "oauth.h"
soramimi0:7ddb56bfde0c 7
soramimi0:7ddb56bfde0c 8EthernetNetIf eth(IpAddr(192,168,0,100), //IP Address
soramimi0:7ddb56bfde0c 9 IpAddr(255,255,255,0), //Network Mask
soramimi0:7ddb56bfde0c 10 IpAddr(192,168,0,1), //Gateway
soramimi0:7ddb56bfde0c 11 IpAddr(192,168,0,1) //DNS
soramimi0:7ddb56bfde0c 12);
soramimi0:7ddb56bfde0c 13NTPClient ntp;
soramimi0:7ddb56bfde0c 14HTTPClient http;
soramimi0:7ddb56bfde0c 15
soramimi0:7ddb56bfde0c 16DigitalOut led(LED1);
soramimi0:7ddb56bfde0c 17
soramimi0:7ddb56bfde0c 18// IMPORTANT: please change the following keys for your application.
soramimi0:7ddb56bfde0c 19
soramimi0:7ddb56bfde0c 20static char const consumer_key[] = "AAAAAAAAAAAAAAAAAAAAAA";
soramimi0:7ddb56bfde0c 21static char const consumer_secret[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
soramimi0:7ddb56bfde0c 22
soramimi0:7ddb56bfde0c 23static char const token_key[] = "00000000-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
soramimi0:7ddb56bfde0c 24static char const token_secret[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
soramimi0:7ddb56bfde0c 25
soramimi0:7ddb56bfde0c 26// get current time and set to system clock
soramimi0:7ddb56bfde0c 27
soramimi0:7ddb56bfde0c 28void reset_time()
soramimi0:7ddb56bfde0c 29{
soramimi0:7ddb56bfde0c 30 Host server(IpAddr(), 123, "ntp.jst.mfeed.ad.jp");
soramimi0:7ddb56bfde0c 31 ntp.setTime(server);
soramimi0:7ddb56bfde0c 32}
soramimi0:7ddb56bfde0c 33
soramimi0:7ddb56bfde0c 34// post message to Twitter
soramimi0:7ddb56bfde0c 35
soramimi0:7ddb56bfde0c 36void tweet(char const *message)
soramimi0:7ddb56bfde0c 37{
soramimi0:7ddb56bfde0c 38
soramimi1:c3f74457cad4 39 std::string uri = "http://api.twitter.com/1/statuses/update.xml";
soramimi0:7ddb56bfde0c 40 uri += "?status=";
soramimi0:7ddb56bfde0c 41 uri += oauth_url_escape(message);
soramimi0:7ddb56bfde0c 42
soramimi0:7ddb56bfde0c 43 std::string req_url;
soramimi0:7ddb56bfde0c 44 std::string postarg;
soramimi0:7ddb56bfde0c 45
soramimi0:7ddb56bfde0c 46 req_url = oauth_sign_url2(uri.c_str(), &postarg, OA_HMAC, 0, consumer_key, consumer_secret, token_key, token_secret);
soramimi0:7ddb56bfde0c 47 oauth_http_post(req_url.c_str(), postarg.c_str());
soramimi0:7ddb56bfde0c 48}
soramimi0:7ddb56bfde0c 49
soramimi0:7ddb56bfde0c 50//
soramimi0:7ddb56bfde0c 51
soramimi0:7ddb56bfde0c 52int main()
soramimi0:7ddb56bfde0c 53{
soramimi0:7ddb56bfde0c 54 eth.setup();
soramimi0:7ddb56bfde0c 55
soramimi0:7ddb56bfde0c 56 reset_time();
soramimi0:7ddb56bfde0c 57
soramimi0:7ddb56bfde0c 58 tweet("Hello, world");
soramimi0:7ddb56bfde0c 59
soramimi0:7ddb56bfde0c 60 while(1) {
soramimi0:7ddb56bfde0c 61 led = 1;
soramimi0:7ddb56bfde0c 62 wait(0.5);
soramimi0:7ddb56bfde0c 63 led = 0;
soramimi0:7ddb56bfde0c 64 wait(0.5);
soramimi0:7ddb56bfde0c 65 }
soramimi0:7ddb56bfde0c 66}