Ok so I'm new to OAuth and I'm creating an app that integrates with Twitter.
I'm using Twitter4j and following their instructions. No problems there.
- I can ask the user to authorize my app
- I exchange a Request Token for an Access Token
- Once the user athorizes the app I serialize the object
Here's how the serialization occurs
FileOutputStream fos = getContext().openFileOutput(fileName, Context.MODE_PRIVATE); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(accessToken); oos.close();
So when it's time to use the Access Token again, I simply desiralize the object and then assign to a new Twitter object and invoke a status update, as below:
AccessToken twitterToken = objectDeserialization();
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(twitterApiKey, twitterApiSecret);
twitter.setOAuthAccessToken(twitterToken);
twitter4j.Status status = twitter.updateStatus("This is sparta! :)");
The problem is that I'm getting a 401.
Everywhere I read I'm convinced that I'm not supposed to go through the whole token exchange thing again. Am I wrong?
Maybe I should simply store the Access Token and the Access Token Secret and create a new object from scratch instead of deserializing an old one?
Appreciate your help :-)