Twitter client that can be directly tweet. (Intermediate server is not required.)

Dependencies:   EthernetInterface HTTPClient-wolfSSL NTPClient OAuth4Tw mbed-rtos mbed wolfSSL

Fork of OAuth4Tw by Atsuya Okazaki

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Wed Jul 08 14:55:36 2015 +0000
Parent:
3:5635abaf69f5
Child:
5:f0c0128cde62
Commit message:
Add GET method API call examples.

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
OAuth4Tw.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.lib	Wed Jul 08 03:10:07 2015 +0000
+++ b/HTTPClient.lib	Wed Jul 08 14:55:36 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/wolfSSL/code/HTTPClient/#7fd621b83b60
+http://developer.mbed.org/users/ban4jp/code/HTTPClient-wolfSSL/#7bc63b8646f6
--- a/OAuth4Tw.lib	Wed Jul 08 03:10:07 2015 +0000
+++ b/OAuth4Tw.lib	Wed Jul 08 14:55:36 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/ban4jp/code/OAuth4Tw/#a057c813fb02
+http://developer.mbed.org/users/ban4jp/code/OAuth4Tw/#1ecf49a46040
--- a/main.cpp	Wed Jul 08 03:10:07 2015 +0000
+++ b/main.cpp	Wed Jul 08 14:55:36 2015 +0000
@@ -13,6 +13,8 @@
               "000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Access token
               "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");     // Access token secret
 
+static char res_buffer[1024] = "";
+
 int main()
 {
     int ret = eth.init(); //Use DHCP
@@ -32,12 +34,13 @@
         return -1;
     }
 
+
     printf("Trying to update time...\n");
 
     time_t ctTime;
     NTPResult result;
 
-    while(1) {
+    while (1) {
         result = ntp.setTime("pool.ntp.org");
         //result = ntp.setTime("pool.ntp.org", NTP_DEFAULT_PORT, 2000);
 
@@ -68,19 +71,40 @@
         wait(5);
     }
 
-    std::string uri = "https://api.twitter.com/1.1/statuses/update.json";
-    uri += "?status=";
-    uri += OAuth4Tw::url_escape("Hello World!");
-    uri += OAuth4Tw::url_escape(" - ");
-    uri += OAuth4Tw::url_escape(ctime(&ctTime));
-    std::string postarg;
-    std::string postres = oa4t.post(uri.c_str(), postarg);
-    printf("postres: %s\n", postres.c_str());
+
+    HTTPText res(res_buffer, sizeof(res_buffer));
 
     while (1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+        {
+            char url[128];
+            char post[128]; //TODO: fix required. need saving memory.
+
+            time(&ctTime);
+
+            snprintf(url, sizeof(url),
+                     "https://api.twitter.com/1.1/statuses/update.json"
+                     "?status=Hello World! - %s", ctime(&ctTime));
+
+            HTTPResult result = oa4t.post(url, post, &res);
+            printf("POST result = %d\n%s\n", result, res_buffer);
+        }
+
+        {
+            const char url[] = "https://api.twitter.com/1.1/users/show.json"
+                               "?screen_name=twitter";
+
+            HTTPResult result = oa4t.get(url, &res);
+            printf("GET result = %d\n%s\n", result, res_buffer);
+        }
+
+        // Wait 300 seconds for next time.
+        for (int t=0; t<300; t++) {
+            myled = 1;
+            wait(0.2);
+            myled = 0;
+            wait(0.8);
+        }
+
+        printf("\n");
     }
 }