How to get user information from twitter in android app?

17,810

Solution 1

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.

Solution 2

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

Solution 3

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)
            {

            }

        });

Solution 4

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

Share:
17,810
Panache
Author by

Panache

Mobile Application Developer

Updated on June 18, 2022

Comments

  • Panache
    Panache about 2 years

    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 name, last name, email, etc. I had done this for facebook with

    facebook.request("me");

    Now how to get user info from twitter? I am using twitter4j-core-android2.2.3.jar. Plz let me know is there a way to get user info.

  • acoustic
    acoustic over 11 years
    don't know what is "editPinCode", don't know what's "oHelper", but why are so many up vote?
  • Rohit
    Rohit almost 11 years
    How to get email id ?
  • pavan kvch
    pavan kvch over 7 years
    It works perfect , even some tutorial websites dont match your answer, thanks
  • D.J
    D.J over 7 years
    I am getting error verifyCredential() to AccountService can not applied.
  • D.J
    D.J over 7 years
    I am not getting email from this.All things I am getting except email.
  • D.J
    D.J over 7 years
    I am not getting email id and mobile number.
  • Devil10
    Devil10 over 6 years
    i think fabric no more support twitter login due to which this account service code gives error. i also geting error and now confused how to do this .