在 android 中使用 oauth 登录 twitter 后,我想知道我的网名。
@SuppressLint("NewApi")
private void Authorize()
{
try {
Consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
Provider = new CommonsHttpOAuthProvider("http://twitter.com/oauth/request_token", "http://twitter.com/oauth/access_token", "http://twitter.com/oauth/authorize");
StrictMode.enableDefaults();
String authUrl = Provider.retrieveRequestToken(Consumer, CALLBACK_URL);
Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
protected void onResume() {
super.onResume();
try
{
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String oauth_verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Consumer.setTokenWithSecret(Consumer.getToken(),Consumer.getTokenSecret());
Provider.retrieveAccessToken(Consumer, oauth_verifier);
HttpParameters params1 = Provider.getResponseParameters();
String userName = params1.getFirst("screen_name");
Toast.makeText(this, "user name >>>>>>>>" + userName, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
抛出前 onResume 函数但 e.getMessage() 为空(Provider.retrieveAccessToken(Consumer, oauth_verifier);错误行)
我怎样才能解决这个问题?