Search code examples
androidtwittertwitter4j

android twitter re-login after user rejected my app


I am working on Twitter integration with my Android app.

Let's imagine a scenario:

  1. User have authorized my app.
  2. I have got access token and saved it (along with token secret) to SharedPreferences.
  3. User opens his Twitter account and kicks out my app.

Obviously, access token becomes invalid at step 3. And attempt to post on behalf of the user results in TwitterException saying "Received authentication challenge is null".

I guess I have to start authorization process again, but how do I know that the saved access token has become invalid?

I think I can analyze TwitterException, but what method specifically? TwitterException has a lot of undocumented methods like getExceptionCode(), getStatusCode(), getErrorCode() and I have no idea which to use to found that my access token has been invalidated.


Solution

  • You can check verify the credentials by calling GET account/verify_credentials, which would tell you information about the token's integrity. Here is the API note on it.