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);