Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

java - How to post image to twitter in android

I want to post an image that is created in my app to twitter. I don't know how to do this and I was wondering if there is an SDK for titter like there is for Facebook? Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First you need to create an app on twitter

here is code to post message on twitter

 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();
        final Twitter twitter = new TwitterFactory(configuration).getInstance();

        new Thread(new Runnable() {

                private double x;

                @Override
                public void run() {
                        boolean success = true;
                        try {
                                x = Math.random();
                                twitter.updateStatus(message +" "+x);
                        } catch (TwitterException e) {
                                e.printStackTrace();
                                success = false;
                        }

                        final boolean finalSuccess = success;

                        callingActivity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                        postResponse.onFinsihed(finalSuccess);
                                }
                        });

                }
        }).start(); 

check this tutorial for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...