2

How can I get the user name, email, location, avatar, etc., of an authenticated user of Twitter in Android via the API?

I wrote the code below, but it always returns null at twitter.showUser(twitter.getId());

public User getUserInfo(Object accessToken) 
{
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(mConsumer.getConsumerKey());
    configurationBuilder.setOAuthConsumerSecret(mConsumer.getConsumerSecret());
    twitter4j.Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance();
    try 
    {
        twitter.setOAuthAccessToken((AccessToken) accessToken);
        return twitter.showUser(twitter.getId());
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
        return null;
    }

I found another question here. People said that unable to retrieve email address of authenticated user of Twitter via api. So, How about other information such as fullname, avatar, phone number (if have),...?

Community
  • 1
  • 1
Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165
  • Have you checked this post which I believe it is a possible duplicate of yours [http://stackoverflow.com/questions/6395945/how-to-get-user-information-from-twitter-in-android-app](http://stackoverflow.com/questions/6395945/how-to-get-user-information-from-twitter-in-android-app) – CRM Jan 06 '12 at 05:06
  • ## You can check below link it's working fine for me ## https://stackoverflow.com/questions/22836358/how-to-get-user-information-form-twitter-api/44491730#44491730 – Shiv Kumar Jun 12 '17 at 05:10

0 Answers0