How to get User Information form Twitter Api

前端 未结 2 1972
滥情空心
滥情空心 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() {
                    @Override
                    public void success(Result 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() {
                @Override
                public void success(Result 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.

提交回复
热议问题