0

I want to post image to twitter on my app. I use "twitter4j" library to post only text. But i cannot find how to post image with text. Thanks for help.

3 Answers3

5
  1. To post a image you have to use media extension of Twitter4j and register your app with either TwitPic or YFrog .
  2. Get KEY and TOKEN from those services and then

    /*
     * Upload File to twitPic and get url . Then append this url to your twitter message.
     */
    public static String upload_twic_pic(File file)
                    throws TwitterException {
            String url = null;
            if (file != null) {
        Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(TWITPIC_KEY).build();
        ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI); //Use ImageUploadFactory
                    url = upload.upload(file);
            }
            return url;
    
Inicio
  • 15
  • 4
kodeshpa
  • 549
  • 5
  • 14
  • It doesn't work. App is crashing because of ImageUpload upload = new ImageUploaderFactory(conf).getInstance(MediaProvider.PLIXI); – Orhun Mert Simsek Mar 15 '12 at 10:47
  • Have u added Media extension jar of Twitter4j ? Also post trace. – kodeshpa Mar 15 '12 at 17:21
  • @user408904 ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI); i get a oauth authorization is required error in this line.Could you help me out. – hemanth kumar Aug 29 '12 at 13:21
1

Here is a link to a one file solution that explains exactly how to integrate picture/text tweets into an android app.

Community
  • 1
  • 1
MindSpiker
  • 1,437
  • 1
  • 14
  • 22
1

You can use socialauth android library

Find SocialAuth Android Here

Tarun Nagpal
  • 964
  • 1
  • 9
  • 25