在android中的oauth之后的twitter用户屏幕名称

时间:2012-03-16 04:27:56

标签: android twitter oauth twitter-oauth

我想知道在使用android中的oauth登录到Twitter后我的屏幕名称。

我使用了OAuth身份验证, 我的代码

new OAuthRequestTokenTask(this,consumer,provider).execute();
public OAuthRequestTokenTask(Context context,OAuthConsumer consumer,OAuthProvider provider) {
    this.context = context;
    this.consumer = consumer;
    this.provider = provider;
}
@Override
protected Void doInBackground(Void... arg0) 
{
try {
    Log.i(TAG, "Retrieving request token from Google servers");
    final String url = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL);
        Log.i(TAG, "Popping a browser with the authorize URL : " + url);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
        context.startActivity(intent);

    } catch (Exception e) {
        Log.e(TAG, "Error during OAUth retrieve request token", e);
    }

    return null;
}

之后,我参与了onNewIntent(Intent intent)

1 个答案:

答案 0 :(得分:2)

使用此代码

private OAuthProvider provider;
private OAuthConsumer consumer;
final Uri uri = params[0];
final 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");
Log.v("user name >>>>>>>>", userName);