Twitter fabric, get user's name

妖精的绣舞 提交于 2019-12-24 15:22:55

问题


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


来源:https://stackoverflow.com/questions/27766084/twitter-fabric-get-users-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!