5

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.

Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
Panache
  • 987
  • 5
  • 16
  • 35

5 Answers5

18

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.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
Panache
  • 987
  • 5
  • 16
  • 35
2
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)
            {

            }

        });
Apurva Kolapkar
  • 1,270
  • 2
  • 16
  • 32
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

rhinds
  • 9,976
  • 13
  • 68
  • 111
1

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

Community
  • 1
  • 1
Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55
0

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.

Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87
  • I am getting error verifyCredential() to AccountService can not applied. – D.J Nov 17 '16 at 12:18
  • I am not getting email id and mobile number. – D.J Nov 21 '16 at 05:34
  • 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 . – Devil10 Dec 28 '17 at 05:58