Twitter fabric, get user's name

2019-07-27 06:04发布

问题:

How do you get a user's name and email after login using twitter's android sdk?

TwitterAuthClient authClient = new TwitterAuthClient();
    authClient.requestEmail(session, new Callback() {
    @Override
    public void success(Result result) {
        Toast.makeText(getApplicationContext(),"Users email : "+result.data.toString,Toast.LENGTH_LONG).show();
    }

    @Override
    public void failure(TwitterException exception) {
      // Do something on failure
    }
});

回答1:

ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(SecretKet);
    User user;
    AccessToken newAcc = new AccessToken(getoken, getokensecret);
    Twitter twitter = new TwitterFactory(builder.build())
            .getInstance(newAcc);
    try {
        String mUserName = twitter.getAccountSettings().getScreenName();
        user = twitter.showUser(mUserName);
        String username = user.getName();
        String email= user.getEmail();
        String oauth_uid = Integer.toString((int) user.getId());

    } catch (TwitterException e) {
        Log.v("ERROR", "API_Get_Twitter_Registration_DATA"+e.toString())
        e.printStackTrace();
    }