How to get User Information form Twitter Api

前端 未结 2 1953
滥情空心
滥情空心 2020-12-06 23:01

I am not able to get information from Twitter Api, not giving any information, I need user profile pic, email and users personal account info, I have tried almost every thin

相关标签:
2条回答
  • 2020-12-06 23:22

    Using this, you are able to get user information

    1.

        twitter_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                client.authorize(SignUpToConnectActivity.this, new Callback<TwitterSession>() {
                    @Override
                    public void success(Result<TwitterSession> result) {
                        String oauth_token_secret = result.data.getAuthToken().secret;
                        String oauth_token = result.data.getAuthToken().token;
                        TwitterSession user = result.data;
                        getUserDetails(user);
                    }
                    @Override
                    public void failure(TwitterException exception) {
                        //
                    }
                });
            }
        })
    

    2.

        public void getUserDetails(TwitterSession twitterSession) {
            Twitter.getApiClient(twitterSession).getAccountService().verifyCredentials(true, false).enqueue(new Callback<User>() {
                @Override
                public void success(Result<User> userResult) {
                    try {
                        User user = userResult.data;
                        String fullname = user.name;
                        String twitterID = user.getId();
                        String userSocialProfile = user.profileImageUrl;
                        String userEmail = user.email;
                        String userFirstNmae = fullname.substring(0, fullname.lastIndexOf(" "));
                        String userLastNmae = fullname.substring(fullname.lastIndexOf(" "));
                        String userScreenName = user.screenName;
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                @Override
                public void failure(TwitterException e) {
                }
            });
        }
    

    Using this, you are able to get user information.

    0 讨论(0)
  • 2020-12-06 23:25

    This works for me Twitter 3+ api calling change

    twitterLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            // Do something with result, which provides a TwitterSession for making API calls                
            TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
            AccountService accountService = twitterApiClient.getAccountService();
            Call<com.twitter.sdk.android.core.models.User> call = accountService.verifyCredentials(true, true, true);
            call.enqueue(new Callback<com.twitter.sdk.android.core.models.User>() {
                @Override
                public void success(Result<com.twitter.sdk.android.core.models.User> result) {
                   //here we go User details
                }
    
                @Override
                public void failure(TwitterException exception) {
                }
            });
        }
    
        @Override
        public void failure(TwitterException exception) {
            // Do something on failure
        }
    });
    
    0 讨论(0)
提交回复
热议问题