1
https://api.twitter.com/1.1/statuses/update_with_media.json

After doing a lots of research on how to post image on twitter,I got this url to post image to twitter.But I didnt know how to use this and what parameters I need to pass.

I also found that

1) Posting to Twitpic is one of the way to post image to twitter,but I didnt know how to use that twitpic library.

I am familiar with posting image to facebook using graph api (url and accesstoken),so I feel that posting image using the above API is much easier.

please suggest me in using the above api

Thanks in advance

user1891910
  • 919
  • 3
  • 18
  • 45

2 Answers2

2

check below code: you have to use use twitter4j-core-2.1.11.jar & twitpic4j.jar

before use this checkthispost.

Login in to twitter using above android code.

You must have to login in twitter and use OAUTH_TOKEN & OAUTH_TOKEN_SECRET in this method. in this i have passed URL same way you can also pass bitmap.

private void hello() {
        // TODO Auto-generated method stub
        String url;

        long result = 0;

        String oth = prefs.getString(OAuth.OAUTH_TOKEN, "");
        String src = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

        Configuration conf = new ConfigurationBuilder()
                .setOAuthConsumerKey(Constants.CONSUMER_KEY)
                .setOAuthConsumerSecret(Constants.CONSUMER_SECRET)
                .setOAuthAccessToken(oth).setOAuthAccessTokenSecret(src)
                .build();

        OAuthAuthorization auth = new OAuthAuthorization(conf,
                conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret(),
                new AccessToken(conf.getOAuthAccessToken(),
                        conf.getOAuthAccessTokenSecret()));

        ImageUpload upload = ImageUpload.getTwitpicUploader(
                Constants.twitpic_api_key, auth);

        Log.d(main_genral_class.TAG, "Start sending image...");

        try {
                url = upload.upload(" ", new URL("https://i.stack.imgur.com/wz0qZ.jpg").openStream(),
                        "some text");
            
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

url is give you URL of uploaded image

for bitmap you can use like : upload.upload(String, inputstream);

Edited

I have checked my code and replace twitter4j-core-2.1.11.jar to twitter4j-core-3.0.3.jar

check full code here

and also change some setting in Twitter App on https://dev.twitter.com

enter image description here

enter code here

its working fine....

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
  • My twitter4j 2.2.5 jar doesnt contains the classes which you have used in this class,I already tried this. – user1891910 Feb 26 '13 at 13:43
  • use twitter4j-core-2.1.11.jar & twitpic4j.jar to execute this code. – Dhaval Parmar Feb 26 '13 at 13:46
  • I also have this jar file twitter4j-core-2.1.11.jar,but its not working now.I am sure because I have used this jar file now.It worked before 2 weeks but its not working now. – user1891910 Feb 26 '13 at 13:48
  • check log proper it give you some exception. you have checked this in android device or in simulator?? – Dhaval Parmar Feb 26 '13 at 13:50
  • oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 301 (Moved Permanently) – user1891910 Feb 26 '13 at 13:54
  • check this: http://stackoverflow.com/a/9987465/1168654 & if you have android OS 4.0 or above them add this "int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT>8){ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }" – Dhaval Parmar Feb 26 '13 at 13:58
  • no,I am testing this in Motorolo 2.3 version,but still I am getting this error.If you see the error report there is some line called Server is moved permanently. – user1891910 Feb 26 '13 at 14:01
  • thank u,I am having twitter2.2.5 ,its working fine but it is not having some classes which are used for twitpic.Could you please find solution for this if possible https://api.twitter.com/1.1/statuses/update_with_media.json – user1891910 Feb 26 '13 at 14:09
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25159/discussion-between-user1891910-and-dhaval-sodha-parmar) – user1891910 Feb 26 '13 at 14:17
1

Have look at this tutorial it solved my whole proble Twit image along text

patient
  • 41
  • 5