本文介绍了Twitter的面料,得到用户的姓名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何使用Twitter的Andr​​oid SDK中获取用户的姓名和电子邮件登录后?

  TwitterAuthClient authClient =新TwitterAuthClient();
    authClient.requestEmail(会话,新的回调(){
    @覆盖
    公共无效成功(结果结果){
        Toast.makeText(getApplicationContext(),用户的电子邮件:+ result.data.toString,Toast.LENGTH_LONG).show();
    }    @覆盖
    公共无效失败(TwitterException除外){
      //请在失败中学习
    }
});


解决方案

  ConfigurationBuilder建设者=新ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(SecretKet);
    用户用户;
    的accessToken的NewAcc =新的accessToken(getoken,getokensecret);
    叽叽喳喳叽叽喳喳=新TwitterFactory(builder.build())
            .getInstance(的NewAcc);
    尝试{
        字符串mUserName = twitter.getAccountSettings()getScreenName()。
        用户= twitter.showUser(mUserName);
        字符串username = user.getName();
        字符串email = user.getEmail();
        串oauth_uid = Integer.toString((int)的user.getId());    }赶上(TwitterException E){
        Log.v(错误,API_Get_Twitter_Registration_DATA+ e.toString())
        e.printStackTrace();
    }

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
    }
});
解决方案
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();
    }

这篇关于Twitter的面料,得到用户的姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 18:28