ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

在Android中使用fabric进行twitter登录AccountService.verifyCredentials()不会将新的Callback()作为参数

2019-06-11 14:11:04  阅读:264  来源: 互联网

标签:android twitter-fabric twitter-login user-data


我想在android twitter成功登录后获取所有用户信息.
对于twiiter登录我使用面料.这是我的代码.

在onCreate()

twitterLoginButton = (TwitterLoginButton) findViewById(R.id.twitterLogin);

twitterLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            //If login succeeds passing the Calling the login method and passing Result object
            twitter_login(result);
        }

        @Override
        public void failure(TwitterException exception) {
            //If failure occurs while login handle it here
            Log.d("TwitterKit", "Login with Twitter failure", exception);
        }
    });

和函数twitter_login()是

public void twitter_login(Result<TwitterSession> result) {

    //Creating a twitter session with result's data
    TwitterSession session = result.data;

    //Getting the username from session
    final String username = session.getUserName();

    //This code will fetch the profile image URL
    //Getting the account service of the user logged in

    /*AccountService ac = Twitter.getApiClient(result.data).getAccountService();
    ac.verifyCredentials(true, true);*/

    Twitter.getApiClient(session)
            .getAccountService()
            .verifyCredentials(true, false, new Callback<User>() {

                @Override
                public void failure(TwitterException e) {
                    //If any error occurs handle it here
                }

                @Override
                public void success(Result<User> userResult) {

                    String imageUrl = userResult.data.profileImageUrl;
                    String email = userResult.data.email;
                    String Name = userResult.data.name;
                    long userid = userResult.data.id;
                    String username = userResult.data.screenName;

                    System.out.println(imageUrl);
                    System.out.println("EMAIL:" + email);
                    System.out.println("Name:" + Name);
                    System.out.println("ID:" + userid);
                    System.out.println("Username:" + username);
                }
            });
}  

在virifyCredentials()它thros一个错误新的Callback()不能应用.
请建议我如何使用这种方法.
提前致谢.

解决方法:

我通过尝试找到了解决方案:

public void success(Result<TwitterSession> result)
{
    TwitterSession   session = result.data;
    Twitter          twitter = Twitter.getInstance();
    TwitterApiClient api     = twitter.core.getApiClient(session);
    AccountService   service = api.getAccountService();
    Call<User>       user    = service.verifyCredentials(true, true);

    user.enqueue(new Callback<User>()
    {
        @Override
        public void success(Result<User> userResult)
        {
            String name = userResult.data.name;
            String email = userResult.data.email;

            // _normal (48x48px) | _bigger (73x73px) | _mini (24x24px)
            String photoUrlNormalSize   = userResult.data.profileImageUrl;
            String photoUrlBiggerSize   = userResult.data.profileImageUrl.replace("_normal", "_bigger");
            String photoUrlMiniSize     = userResult.data.profileImageUrl.replace("_normal", "_mini");
            String photoUrlOriginalSize = userResult.data.profileImageUrl.replace("_normal", "");
        }

        @Override
        public void failure(TwitterException exc)
        {
            Log.d("TwitterKit", "Verify Credentials Failure", exc);
        }
    });
}

标签:android,twitter-fabric,twitter-login,user-data
来源: https://codeday.me/bug/20190611/1219109.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有