Issue
I'm making an Activity that uses OAuth to authorize with Twitter and send a tweet (edit: I'm using Twitter4j). To do this I must first request a RequestToken from Twitter, then the user goes out to the browser to authorize the app, and I'm sent back to onNewIntent() with a authorization string in the intent.getData(). I use the RequestToken and the string to form a valid AccessToken.
As I understand it, since my Activity is leaving focus while the user kicks out to the browser, there's no guarantee that my session state is going to be available once I return to onNewIntent(), which means I may no longer have a RequestToken with which to make the AccessToken. In an ideal world I would just save the RequestToken to SharedPreferences and pull it later when I need it. However after looking into it, it would be highly non-trivial to do this, as I really have no way of deconstructing/reconstructing a RequestToken object (AFAIK, please correct me if you know otherwise, because this would be much more prefereable).
So I'm looking into implementing onSaveInstanceState() and onRestoreInstanceState() but I'm just not grasping the documentation I've read. How can I guarantee that, in this case, my RequestToken object (and preferably the rest of my state) is around for me to use when I arrive at onNewIntent()?
Thanks, == Matt
Solution
It turns out I don't need to persist the RequestToken, because I can build an AccessToken without it. An AccessToken can be built with A) RequestToken + oauth_verifier, or B) access_token + access_token_secret strings.
So I use the RequestToken to get the oauth_verifier, and make an AccessToken with that, then I pull the access_token and access_token strings from the AccessToken, and store those. Later I can rebuild the AccessToken with the stored access_token and access_token_secret strings.
Answered By - mmseng
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.