having to change to the OAuthSignpostClient

189 views
Skip to first unread message

randy

unread,
Apr 11, 2011, 12:48:11 PM4/11/11
to JTwitter
I have this jtwitter app that i have created.
I have my customers twitter username/password in my database
I would connect and get their status and then post it on their website
that we provide

this is now broke and i get the error i have use OAuth
I tried following the example but get the error
"winterwell.jtwitter.TwitterException:
oauth.signpost.exception.OAuthExpectationFailedException: Authorized
request token or token secret not set. Did you retrieve an authorized
request token before?"

there was another thread that talked alittle about it, but i was not
completely sure what they where talking about
https://groups.google.com/group/jtwit/browse_thread/thread/4f06db05cbadd940?hl=en

it talks about "verifying the Authorization Code" , but i am not sure
how to do that

i was following the example on
http://www.winterwell.com/software/jtwitter.php

thanks for any help

vic

unread,
Apr 12, 2011, 1:05:42 AM4/12/11
to JTwitter
Do you mind posting your code? Thanks.

On Apr 11, 12:48 pm, randy <randy.par...@unitnet.com> wrote:
> I have this jtwitter app that i have created.
> I have my customers twitter username/password in my database
> I would cD
> this is now broke and i get the error i have use  OAuth
> I tried following the example but  get the error
> "winterwell.jtwitter.TwitterException:
> oauth.signpost.exception.OAuthExpectationFailedException: Authorized
> request token or token secret not set. Did you retrieve an authorized
> request token before?"
>
> there was another thread that talked alittle about it, but i was not
> completely sure what they where talking abouthttps://groups.google.com/group/jtwit/browse_thread/thread/4f06db05cb...
>
> it talks about "verifying the Authorization Code" , but i am not sure
> how to do that
>
> i was following the example onhttp://www.winterwell.com/software/jtwitter.php
>
> thanks for any help

randy

unread,
Apr 12, 2011, 7:52:26 AM4/12/11
to JTwitter
sure all i am doing so far is the code from the example: ( i
appreciate the help)

try{

OAuthSignpostClient oauthClient = new
OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET, "oob");
oauthClient.setAuthorizationCode(keyPin);
Twitter twitter = new Twitter("paries",oauthClient);
String tStatus = twitter.getStatus().getText();
System.out.println(tStatus);
}catch(Exception ex){
ex.printStackTrace();
}

and the exception is
winterwell.jtwitter.TwitterException:
oauth.signpost.exception.OAuthExpectationFailedException: Authorized
request token or token secret not set. Did you retrieve an authorized
request token before?
at
winterwell.jtwitter.OAuthSignpostClient.setAuthorizationCode(OAuthSignpostClient.java:
309)
at com.unitnet.twitter.twitter.main(twitter.java:79)
Caused by: oauth.signpost.exception.OAuthExpectationFailedException:
Authorized request token or token secret not set. Did you retrieve an
authorized request token before?
at
oauth.signpost.AbstractOAuthProvider.retrieveAccessToken(AbstractOAuthProvider.java:
91)
at
winterwell.jtwitter.OAuthSignpostClient.setAuthorizationCode(OAuthSignpostClient.java:
305)
Message has been deleted

vic

unread,
Apr 13, 2011, 3:12:27 AM4/13/11
to JTwitter
The problem is that you are trying to set a pin, when the pin has not
been retrieved by the user. More on this below.

The workflow for oauthorization is as follows:
1. Get a consumer key and secret by registering a (dummy) app at
dev.twitter.com. Choose the "client" method if you want to use the
"oob" (out of band) option. Use the values you get to set
JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET. Then do:

OAuthSignpostClient oauthClient = new
OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET, "oob");

2. Get an authorization pin. This pin is a nonce (one time use only)
that is given after the user verifies using his Twitter
username and password. This is done by:

oauthClient.authorizeDesktop(); //should open a webpage where use can
authenticate on Twitter. He/she'll then be given a pin

// get the pin and enter it here
String v = oauthClient.askUser("Please enter the verification PIN from
Twitter");

3. If the pin is correct, then it is used in the method below to
request an access key and access secret that identifies the
user who enterer his/her username and password. The method also
'saves' the access key and secret inside the
oauthClient object:

oauthClient.setAuthorizationCode(v);

Since the keys are persistent, you can get them from the oauthClient
by doing something like the following. ACCESS_TOKEN
and ACCESS_KEY are Strings. You can then save them and use them later
so that you don't have to request a pin everytime:
oauthClient.setAuthorizationCode(verifier);
String[] pair = oauthClient.getAccessToken();

ACCESS_TOKEN=pair[0];
ACCESS_KEY=pair[1];

From there, you can do something like Twitter twitterUser = new
Twitter("username",oauthClient);

You can also create a new oauthClient by doing:


OAuthSignpostClient newOauthClient = new
OAuthSignpostClient(JTWITTER_OAUTH_KEY,JTWITTER_OAUTH_SECRET,
ACCESS_TOKEN, ACCESS_KEY);//the last two are from above

Then Twitter twitter = new Twitter("username",newOauthClient);
Reply all
Reply to author
Forward
0 new messages