Twitter结构,获得用户的名字

时间:2015-01-04 13:38:34

标签: java android twitter-fabric

使用Twitter的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 个答案:

答案 0 :(得分:4)

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();
    }