Pages: [1]   Go Down
Author Topic: Arduino Twitter Library with OAuth Support  (Read 1772 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
i am working in a university project, and i want to use Twitter API with Oauth authorization from arduino, i tried with Authorizing a request from https://dev.twitter.com/docs/auth/authorizing-request but i get bad request let see the code here
http://arduino.cc/forum/index.php/topic,149669.0.html, it  doesn't work.with and without F();

so i need to  try other things
i find this library to get OAUTH autorization for Twitter API v1.1:http://www.markkurossi.com/ArduinoTwitter/index.html,
and i modified the library for a WifiShield. and i try with this code:
 
Code:
twitter.set_twitter_endpoint(PSTR("pai.twitter.com"),PSTR("/1.1/statuses/update.json"), server_ip, 80, false);
 
   twitter.set_client_id(PSTR("******CONSUMER KEY*********"),PSTR("****CONSUMER SECRET*********"));
   twitter.set_account_id(PSTR("***ACCESS TOKEN*************"),PSTR("********TOKEN SECRECT*************"));
   twitter.set_account_id(256, 384);

 delay(10000);
 
 if(twitter.is_ready())
 {
   setTime(twitter.get_time());
   if (twitter.post_status("Hello, Getting started Twitter Library with OAuth Support !"))
   {
       Serial.println("Status updated");
   }
   else
   {
       Serial.println("Update failed");
   }
 }
 
}
so the problem is that i can't post with this code, but i can get time form twitter server; so it s connect but don t post the message.
 i need to know if this library work with Ethernet Shield??
any help please....


 
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, did you follow all the instructions in the ArduinoTwitter library page, including the part in Java? You should consider that the two ways to pass the account_id are alternative, and the second one only applies if you saved the credentials in the EEPROM.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
i have not did the part of java, i got all the parametre valu consumer and token from the aplication in https://dev.twitter.com/
i am trying to compile the java example bat i have an error. i am using Net beans. the error that i have is:
Code:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - package oauth.signpost does not exist
at Main.<clinit>(Main.java:6)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
normally the java example is for  configuring the twitter application's consumer key and consumer secret for the oauth-signpost's OAuthConsumer.
(it can be done in twitter account dev???, can i run the java example other way??)
there is other way to do it???
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do i have to run the example on the arduino board?

 Download OAuthTwitterExample.zip from oauth-signpost wiki
Open src/Main.java and configure you twitter application's (the software running on the Arduino board) consumer key and consumer secret for the oauth-signpost's OAuthConsumer:
Compile src/Main.java
Run OAuthTwiterExample and follow the instructions:

any help with  this step???

thanks a lot..
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cannot help with the Java application, but as you said the configuration can be done online, and the Java application is only used as a verification tool. You may find other examples, in other languages as well, on the Twitter's developers site.

Coming to the Arduino application, the main issue is that here
Code:
   twitter.set_client_id(PSTR("******CONSUMER KEY*********"),PSTR("****CONSUMER SECRET*********"));
   twitter.set_account_id(PSTR("***ACCESS TOKEN*************"),PSTR("********TOKEN SECRECT*************")); // first form
   twitter.set_account_id(256, 384); // second, alternative form
set_account() is called twice. But you should use either the first form, with your access token and token secret passed as arguments, or the second, if these credentials are already stored in the EEPROM of the Arduino. I believe you should use the first, so you may just delete the last line and try again. If things don't work, however, you'll need an independent way to confirm that you are passing the right parameters, and this is why you should get a working Java application.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,
thanks a lot for your help first.
i tried what you said and this is the result
the code
Code:
#include <Twitter.h>
#include <EEPROM.h>
#include <Time.h>
#include <WiFi.h>
#include <sha1.h>
#include <iterator>

IPAddress server_ip(199,59,150,39);
char buffer[512];
Twitter twitter(buffer,sizeof(buffer));
char ssid[]="*******";
char pass[]="***********";
WiFiClient client;

void setup()
{
   WiFi.begin(ssid,pass);
   Serial.begin(9600);
   Serial.println("connecting to wlan ...");
   delay(1000);
   twitter.set_twitter_endpoint(PSTR("pai.twitter.com"),PSTR("/1.1/statuses/update.json"), server_ip, 80, false);
   twitter.set_client_id(PSTR("*************************"),PSTR("****************************************"));
   twitter.set_account_id(PSTR("****************************************"),PSTR("********************************************"));
   //twitter.set_account_id(256, 384);

 delay(10000);
  if(twitter.is_ready())
 {
   Serial.println("posting .......");
   if (twitter.post_status("Hello, Getting started Twitter Library with OAuth Support !"))
   {
       Serial.println("Status updated");
   }
   else
   {
       Serial.println("Update failed");
       while (client.available())
       {
         char c=client.read();
         Serial.print(c);
       }
   }
 }
}
 

void loop()
{
   setTime(twitter.get_time());
   if(timeStatus()!= timeNotSet)
  {
    digitalClockDisplay(); 
 }
  if(timeStatus()!= timeNotSet)
  {
    digitalClockDisplay(); 
  }
 
  delay(1000);
}
void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(dayStr(weekday()));
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(monthShortStr(month()));
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

Reponse
Code:
connecting to wlan ...
posting .......
server: tfe
HTTP/1.1 404 Not Found
date: Fri, 29 Mar 2013 15:47:08 UTC
server: tfe
set-cookie: guest_id=v1%3A136457202842068951; Domain=.twitter.com; Path=/; Expires=Sun, 29-Mar-2015 15:47:08 UTC
Content-Length: 0
Connection: close


Update failed
15:47:09 Friday 29 Mar 2013
15:47:09 Friday 29 Mar 2013
15:47:10 Friday 29 Mar 2013
15:47:10 Friday 29 Mar 2013
15:47:11 Friday 29 Mar 2013


Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm,

twitter.set_twitter_endpoint(PSTR("pai.twitter.com"),PSTR("/1.1/statuses/update.json"), server_ip, 80, false);
 smiley-confuse
Logged

Pages: [1]   Go Up
Jump to: