Hi, I was trying to make a update my user status, but It was returning
an exception, I'm thinking it's because my username is already
registered for my application, and this way, the new token that I
request is not being accepted, since twitter is waiting for the other
token registered for my user.
Here's the exception
Exception in thread "main" twitter4j.TwitterException: Authentication
credentials were missing or incorrect.
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<request>/statuses/update.xml</request>
<error>Invalid / expired Token</error>
</hash>
at twitter4j.http.HttpClient.httpRequest(HttpClient.java:431)
at twitter4j.http.HttpClient.post(HttpClient.java:350)
at twitter4j.Twitter.updateStatus(Twitter.java:1272)
at Main.main(Main.java:36)
here's the code (the same example with small changes from the Yusuke's
site)
import java.io.*;
import twitter4j.*;
import twitter4j.http.*;
public class Main {
public static void main(String args[]) throws Exception{
Twitter twitter = new Twitter();
twitter.setHttpProxy("proxyarray.tivit.corp", 8080);
twitter.setOAuthConsumer("CWU2su0eWaLQ5XV3vqfXQg",
"jEa3Ej1G7HryApW7D1j5TrJ6Toak7USsPUMBl2EEM");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader
(System.in));
while (null == accessToken) {
System.out.println("Open the following URL and grant
access to your
account:");
System.out.println(requestToken.getAuthorizationURL());
System.out.print("Hit enter when it's done.[Enter]:");
br.readLine();
try{
accessToken = requestToken.getAccessToken();
} catch (TwitterException te) {
if(401 == te.getStatusCode()){
System.out.println("Unable to get the
access token.");
}else{
te.printStackTrace();
}
}
}
//persist to the accessToken for future reference.
//storeAccessToken(twitter.verifyCredentials().getId() , at);
Status status = twitter.updateStatus("Testando TwitterFm");
System.out.println("Successfully updated the status to [" +
status.getText() + "].");
System.exit(0);
}
}
as you can see, I didn't persisted the AccessToken, because I don't
want to. Since I'm planning on doing a desktop application (I can't
afford a jsp server) I don't want these tokens to be stored on user's
computer, or at least I want them to have the choice, if they want or
not.
so is there a way to recover from twitter the already registered
token? or am I doomed?