JTwitter - upgrading to the new Authentication

61 views
Skip to first unread message

Scott

unread,
Sep 30, 2010, 8:10:07 AM9/30/10
to JTwitter
Hi,

I like a lot of other people am trying to upgrade my app to the new
Authentication. The app runs every hour and looks at some
environmental stats and sends a tweet based on what it finds.

I am trying to come to grips with the new authentication with no luck
so was hoping someone could give me some help. So far I have:

1. Registered the app with Twitter and received a ConsumerKey and
ConsumerSecret.
2. Run the example code, this re-directs me to the Twitter site which
returns a numeric pin or key
3. Managed to get Daniels status but not to set my status.

So my question is, how do I do the validation once and then just send
messages or tweets via the program without having to re-validate each
time the program runs, that is to store the credentials for future
use?? Sorry to appear as a newbie but the old system worked just fine.

This is what I am trying:

----------------------------------------

String keyPin = "1234567";
String message = "Hello";
String consumerKey = "ABCDEFG";
String consumerSecret = "ZGDFETER";
String twitterAccountName = "myName";

try{

OAuthSignpostClient oauthClient = new
OAuthSignpostClient(consumerKey, consumerSecret, "oob");
oauthClient.setAuthorizationCode(keyPin);
Twitter twitter = new Twitter(twitterAccountName,
oauthClient);
twitter.setStatus(message);


}catch( Exception e){
e.printStackTrace();
}
-----------------------------------

and I 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?



Thanks for any help!



Scott.

Dobes Vandermeer

unread,
Sep 30, 2010, 12:03:58 PM9/30/10
to jt...@googlegroups.com
After verifying the Authorization Code the first time, you have to
save the token key and secret in addition to your consumer key and
secret.

Next time you create the oauthClient you use those four strings
instead of the authorization code.

Basically, the authorization code can only be used once, after which
your oauthClient will have a token key you can save for future use.

I hope that helps.

I have made an app that uses JTwitter and OAuth to retweet specific
tweets from people, you can take a look at
http://github.com/dobesv/retweetster it might serve as a useful
example.

Cheers,

Dobes

Scott

unread,
Sep 30, 2010, 9:53:33 PM9/30/10
to JTwitter
Hi Dobes,

Thanks for the help, have solved it now!

For those following what I did was to register a dummy app with
twitter, copy down the ConsumerKey and ConsumerSecret, there is now a
get Access Token button that will return the AccessToken and
AccessSecret, use these four to create a client and then off you go.

Happy to share more if anyone is interested.

Thanks guys for a great product and great support!

Cheers,



Scott.

Dobes Vandermeer

unread,
Sep 30, 2010, 11:39:44 PM9/30/10
to jt...@googlegroups.com

Ah that get access token thing seems like a major time saver.  Thanks for sharing that.

Reply all
Reply to author
Forward
0 new messages