Search code examples
androidmediatwitter4j

How to share image along with some text in android twitter?


I want to add an image along with some text from my android native app. I saw several links that propose intent sharing.but i don't want that. How i can obtain this using twitter4j. I found a twitpic jar that allows image sharing. It is working ,but it share that in facebook also and it shows twitpic in tweet.Can we avoid that facebook sharing? or is it possible to share image using twitter4j_media_support jar?


Solution

  • Take a look at this tutorial.

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    
    configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
    
    configurationBuilder.setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
    
    configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken((context)));
    
    configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
    
    Configuration configuration = configurationBuilder.build();
    
    Twitter twitter = new TwitterFactory(configuration).getInstance();
    
    StatusUpdate status = new StatusUpdate(message);
    
    status.setMedia(file); // set the image to be uploaded here.
    
    twitter.updateStatus(status);