Android twitter4j upload image

前端 未结 1 761
夕颜
夕颜 2020-12-08 03:19

I have an android app through which I can successfully update the twitter status. I am using it to share links to a webpage which displays an image. I think it will be nice

相关标签:
1条回答
  • 2020-12-08 03:54

    I had the same requirement sometimes back and finally come with the function may be it will help you too.

    /**
     * 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  {
        try{
            StatusUpdate status = new StatusUpdate(message);
            status.setMedia(file);
            twitter.updateStatus(status);}
        catch(TwitterException e){
            Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
            throw e;
        }
    }
    

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

    0 讨论(0)
提交回复
热议问题