我正在集成Twitter
到 android 应用程序中。当我尝试getOAuthAccessToken()
在代码中调用方法时,它会抛出NullPointerException
.
// Parse the Intent data to get OAuth verifier.
public void getTwitterVerifier(final Intent intent) {
Log.d(TAG, "Trying to get twitter verifier.");
if (!isAlreadyLoggedInToTwitter()) {
try {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Uri uri = intent.getData();
// OAuth verifier
final String verifier = uri
.getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);
Log.d(TAG, "Request token : " + requestToken);
Log.d(TAG, "Verifier : " + verifier);
// Get the access token
AccessToken accessToken = twitter
.getOAuthAccessToken(requestToken, verifier); // THROWS EXCEPTION HERE.
// After getting access token and access token
// secret store them in shared preferences
Editor e = preferences.edit();
e.putString(TWITTER_OAUTH_TOKEN_KEY,
accessToken.getToken());
e.putString(TWITTER_OAUTH_SECRET_KEY,
accessToken.getTokenSecret());
// Set status to logged in
e.putBoolean(TWITTER_LOGGED_IN, true);
e.commit();
Log.d(TAG,
"Twitter OAuth Token"
+ accessToken.getToken());
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Log
导致问题的行上方的语句显示非空值:
Request token : OAuthToken{token='6lneq6DKm0O9qg9rUJKuv4Coc6CA2GE0XwM4QPa3c', tokenSecret='p2ATEcqobFrHS2y6DyqSZkQqnxljKq8ObKGfEPcUL20', secretKeySpec=null}
Verifier : ZtTBbMAXTIBSlL3zX57WTeLraRg53mpgfrXVLUA4
我无法弄清楚问题所在。任何帮助将不胜感激。