Sample code using OAuth library for twitter.
Dependencies: EthernetNetIf OAuth4Tw mbed HTTPClient
Twitter sample code using OAuth library: http://mbed.org/users/takahashim/libraries/OAuth4Tw/
By using the OAuth library, you can directly tweet without proxy services such as supertweet.net.
Set up on Twitter.com
- Create a Twitter account if needed.
- Access "Twitter Developers" web site by using the account: https://dev.twitter.com/
- "Create a new application" in "My applications" menu. Then, fill the form with appropriate information.
- "(Re)create my access token" with an appropriate "Access level." "Read and Write" is required for posting tweets. You can change the Access level in "Application Type" on "Settings" tab later.
- Note "Consumer key", "Consumer secret", "Access token", and "Access token secret" described in "Details" tab.
Set up on mbed
- Import the sample program
- Replace "Consumer key", "Consumer secret", "Access token", and "Access token secret" in main.cpp with yours.
- Compile the code with libraries and install the output binary into your mbed.
main.cpp@0:00a2d3570824, 2012-05-20 (annotated)
- Committer:
- geodenx
- Date:
- Sun May 20 14:51:54 2012 +0000
- Revision:
- 0:00a2d3570824
Add a library link.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
geodenx | 0:00a2d3570824 | 1 | #include <string.h> |
geodenx | 0:00a2d3570824 | 2 | #include "mbed.h" |
geodenx | 0:00a2d3570824 | 3 | #include "EthernetNetIf.h" |
geodenx | 0:00a2d3570824 | 4 | #include "OAuth4Tw.h" |
geodenx | 0:00a2d3570824 | 5 | |
geodenx | 0:00a2d3570824 | 6 | DigitalOut myled(LED1); |
geodenx | 0:00a2d3570824 | 7 | EthernetNetIf eth; |
geodenx | 0:00a2d3570824 | 8 | |
geodenx | 0:00a2d3570824 | 9 | int main() { |
geodenx | 0:00a2d3570824 | 10 | EthernetErr ethErr = eth.setup(); |
geodenx | 0:00a2d3570824 | 11 | if (ethErr) { |
geodenx | 0:00a2d3570824 | 12 | printf("Error %d in setup.\n", ethErr); |
geodenx | 0:00a2d3570824 | 13 | return -1; |
geodenx | 0:00a2d3570824 | 14 | } |
geodenx | 0:00a2d3570824 | 15 | |
geodenx | 0:00a2d3570824 | 16 | OAuth4Tw oa4t("XXXXXXXXXXXXXXXXXXXXXX", // Consumer key |
geodenx | 0:00a2d3570824 | 17 | "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // Consumer secret |
geodenx | 0:00a2d3570824 | 18 | "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token |
geodenx | 0:00a2d3570824 | 19 | "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // Access token secret |
geodenx | 0:00a2d3570824 | 20 | std::string uri = "http://api.twitter.com/statuses/update.xml"; |
geodenx | 0:00a2d3570824 | 21 | uri += "?status="; |
geodenx | 0:00a2d3570824 | 22 | uri += OAuth4Tw::url_escape("Hello World!"); |
geodenx | 0:00a2d3570824 | 23 | std::string postarg; |
geodenx | 0:00a2d3570824 | 24 | std::string postres = oa4t.post(uri.c_str(), postarg); |
geodenx | 0:00a2d3570824 | 25 | printf("postres: %s\n", postres.c_str()); |
geodenx | 0:00a2d3570824 | 26 | |
geodenx | 0:00a2d3570824 | 27 | while (1) { |
geodenx | 0:00a2d3570824 | 28 | myled = 1; |
geodenx | 0:00a2d3570824 | 29 | wait(0.2); |
geodenx | 0:00a2d3570824 | 30 | myled = 0; |
geodenx | 0:00a2d3570824 | 31 | wait(0.2); |
geodenx | 0:00a2d3570824 | 32 | } |
geodenx | 0:00a2d3570824 | 33 | } |