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.
Revision 0:00a2d3570824, committed 2012-05-20
- Comitter:
- geodenx
- Date:
- Sun May 20 14:51:54 2012 +0000
- Commit message:
- Add a library link.
Changed in this revision
diff -r 000000000000 -r 00a2d3570824 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Sun May 20 14:51:54 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mamezu/code/EthernetNetIf/#0f6c82fcde82
diff -r 000000000000 -r 00a2d3570824 HTTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient.lib Sun May 20 14:51:54 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mamezu/code/HTTPClient/#62fac7f06c8d
diff -r 000000000000 -r 00a2d3570824 OAuth4Tw.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OAuth4Tw.lib Sun May 20 14:51:54 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/takahashim/code/OAuth4Tw/#0048b264a3ad
diff -r 000000000000 -r 00a2d3570824 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 20 14:51:54 2012 +0000 @@ -0,0 +1,33 @@ +#include <string.h> +#include "mbed.h" +#include "EthernetNetIf.h" +#include "OAuth4Tw.h" + +DigitalOut myled(LED1); +EthernetNetIf eth; + +int main() { + EthernetErr ethErr = eth.setup(); + if (ethErr) { + printf("Error %d in setup.\n", ethErr); + return -1; + } + + OAuth4Tw oa4t("XXXXXXXXXXXXXXXXXXXXXX", // Consumer key + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", // Consumer secret + "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // Access token secret + std::string uri = "http://api.twitter.com/statuses/update.xml"; + uri += "?status="; + uri += OAuth4Tw::url_escape("Hello World!"); + std::string postarg; + std::string postres = oa4t.post(uri.c_str(), postarg); + printf("postres: %s\n", postres.c_str()); + + while (1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +}
diff -r 000000000000 -r 00a2d3570824 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun May 20 14:51:54 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479