Can we post image on twitter using twitter API in Android?

I had successfully integrate twitter API and I am able to post text from my device but I want to know two things

  1. Is is possible to post Image on twitter using API in Android ?

  2. Gradle - selective module compilation (reuse jar otherwise)
  3. Failed to resolve:
  4. Android Studio - Can flavours share code with other flavours?
  5. how to set the output image use
  6. Failed to find style vpiCirclePageIndicatorStyle
  7. Notification deleteIntent does not work
  8. In twitter we used OAuth.OAUTH_TOKEN and OAuth.OAUTH_TOKEN_SECRET tokens.I passing token values on second argument in below code is it ok ? or I have to leave it blank ?

    String token = prefs.getString(OAuth.OAUTH_TOKEN, OAuth_token_key);
    String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, OAuth_token_secret);

I searched to know whether is it possible to post image on twitter using twitter API in Android but I have not found any link that I know whether it is possible or not.

I got one similar post image issue for iPhone and there is a answer also. I don’t know about iPhone so I can’t know weather it is right answer or not.Here is a link of similar question of post image for iPhone

Please help me out from this issue.

Related posts:

How to get a view from within Espresso to pass into an IdlingResource?
Fresco add Bitmap to Cache programatically
Android ActionBar compatibility: MenuItem.setActionView(View)
What special powers does ashmem have?
Android options menu icon won't display
Commiting google-services.json to GitHub
  • Animate layout change of bottom sheet
  • How to get String from JSONObject without Specific Name
  • Cannot install debug and release version on same device
  • Modifying the color of an android drawable
  • Get Cover Photo using Facebook API
  • Customizing ActionBar Tabs on Android 4
  • 3 Solutions collect form web for “Can we post image on twitter using twitter API in Android?”

    Yes You can post the Image on the Twitter.

    AIK, there are two methods to upload the photo to the Twitter.

    With First you have to implemente the Twitter API and use this Link to upload the Photot to the Twitter.

    Sorry for the Example. as i dont get any example for how to use this.

    With Second you can do this with the help of the twitPic4j API.
    Just add the API for twitPic4j and write below code to upload the photo.


    File picture = new File(APP_FILE_PATH + "/"+filename+".jpg");  
    // Create TwitPic object and allocate TwitPicResponse object 
    TwitPic tpRequest = new TwitPic(TWITTER_NAME, TWITTER_PASSWORD); 
    TwitPicResponse tpResponse = null;  
    // Make request and handle exceptions                            
    try {         
            tpResponse = tpRequest.uploadAndPost(picture, customMessageEditText.getText()+"");
    catch (IOException e) {         
           Toast.makeText(getApplicationContext(), "Please enter valid username and password.", Toast.LENGTH_SHORT).show();
    catch (TwitPicException e) {         
            Toast.makeText(getApplicationContext(), "Invalid username and password.", Toast.LENGTH_SHORT).show();
            Toast.makeText(getApplicationContext(), "Please enter valid Username and Password.", Toast.LENGTH_SHORT).show();
    // If we got a response back, print out response variables                               
    if(tpResponse != null) {         
                Toast.makeText(getApplicationContext(), "Photo posted on Twitter.",Toast.LENGTH_SHORT).show();

    Above code works in for my case.

    Hope you got the sollution with the second one and i dont know how to use the first one.

    Enjoy. 🙂


    If still it not works for you and try some project listed below:

    Example 1

    Example 2

    Example 3

    Example 4

    Hope that will help you.

    Happy Coding.


    FOR erdomester and Updated answer


    Please check my first link given with Example1 and its api: Twitter4J
    So, if any library that stop giving functionality to upload image on twitter, you can use other library for same. Please check and read regrading Twitter4j.

    Check Twitter4J API to upload file to Twitter: Twitter4j Image Upload

    For instance help you can also check below code to upload image file on Twitter.

    Code to upload Image:

     * To upload a picture with some piece of text.
     * @param file The file which we want to share with our tweet
     * @param message Message to display with picture
     * @param twitter Instance of authorized Twitter class
     * @throws Exception exception if any
    public void uploadPic(File file, String message,Twitter twitter) throws Exception  {
            StatusUpdate status = new StatusUpdate(message);
        catch(TwitterException e){
            Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
            throw e;

    I hope this will help you more for your query.

    Thanks to eredomester to notify me that tweetpic is no more working for Twitter. But please dont do downvote to answer untill you have not fully search on the given reply. Given library Twitter4J in Example1 gives clear idea about uploading image to twitter and you can easily implement it.

    For more help and code you can also check: Twitter Upload media

    Note: To use this please make sure you have latest jar file. I have used twitter4j-core-2.2.5.jar or more for this.

    Please comment me instead of downvoting this answer, if you facing any issue in this.

    Is is possible to post Image on twitter using API in Android ?

    Yes you can upload Images to Twitter after successful Authentication Using Twitter Media Uplload.

    In twitter we used OAuth.OAUTH_TOKEN and OAuth.OAUTH_TOKEN_SECRET
    tokens.I passing token values on second argument in below code is it
    ok ? or I have to leave it blank ?

    You should add both Token and Token Secret Key it will be useful for setTokenWithSecret methos of Tiwtter in which you have to send both Token and Token Secret..

    Yes you can post image on twitter using Twitter api like twitter4j but I will suggest you to do using HttpPost class and DefaultHttpClient class because its good in practice and you dont need to add any external twitter api to it.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.