How to get user information from twitter in android app?

前端 未结 5 1707
囚心锁ツ
囚心锁ツ 2020-12-01 19:59

I am integrating twitter in my android app. I am able to authorize the app for the user. Now, I am looking for the API which gives me logged users information like first nam

相关标签:
5条回答
  • 2020-12-01 20:30

    Finally I got user information.

    use the access token you get after

    accessToken = twitterConnection.getOAuthAccessToken
        (requestToken,editPinCode.getText().toString());
    
    oHelper.storeAccessToken(accessToken);
    
    Log.i("Access Token:", accessToken.getToken());
    
    Log.i("Access Secret:", accessToken.getTokenSecret());
    
    long userID = accessToken.getUserId();
    
    User user = twitterConnection.showUser(userID);
    
    user.getName();
    

    Thanks.

    0 讨论(0)
  • 2020-12-01 20:34
    Twitter.getApiClient(session).getAccountService().verifyCredentials(true, false).enqueue(new Callback<User>()
            {
                @Override
                public void success(Result<User> userResult)
                {
                    try
                    {
                        User user = userResult.data;
    //                         twitterImage = user.profileImageUrl;
                    } catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
    
                @Override
                public void failure(TwitterException e)
                {
    
                }
    
            });
    
    0 讨论(0)
  • 2020-12-01 20:34

    You cannot get Email from the twitter OAuth unless or untill your app is whitelisted. For more Info Email ID from Twitter

    0 讨论(0)
  • 2020-12-01 20:35

    There are a few tutorials here that can help you get an app running with twitter..

    if you just need to retrieve info for a specific user, you can look here (includes source code):

    Basic Adroid Twitter Integration

    If you want to interact with twitter (e.g. post updates etc) then you will need to setup OAuth connection:

    Android and Twitter integratin using OAuth

    0 讨论(0)
  • 2020-12-01 20:47

    You can check bellow code: To get user info you can use Twitter Fabric SDK. Its documentation is here and here

     twitterButton.setCallback(new Callback<TwitterSession>() {
                @Override
                public void success(Result<TwitterSession> result) {
                    // Do something with result, which provides a TwitterSession for making API calls
                    AccountService ac = Twitter.getApiClient(result.data).getAccountService();
                    ac.verifyCredentials(true, true, new Callback<com.twitter.sdk.android.core.models.User>() {
                        @Override
                        public void success(Result<com.twitter.sdk.android.core.models.User> result) {
                            String imageUrl = result.data.profileImageUrl;
                            String email = result.data.email;
                            String userName = result.data.name;
                            System.out.println(imageUrl);
                            System.out.println(email);
                            System.out.println(userName);
                        }
    
                        @Override
                        public void failure(TwitterException e) {
                            Log.d("ls",e.getMessage());
                        }
                    });
    
                }
    
                @Override
                public void failure(TwitterException exception) {
                    Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.app_name),
                            Toast.LENGTH_SHORT).show();
                }
            });
    

    Here twitterButton is import com.twitter.sdk.android.core.identity.TwitterLoginButton; In this response you can get All credential without user Email.

    0 讨论(0)
提交回复
热议问题