如何在android中将图像发布到推特 [英] How to post image to twitter in android

查看:27
本文介绍了如何在android中将图像发布到推特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将在我的应用中创建的图像发布到 Twitter.我不知道该怎么做,我想知道是否有像 Facebook 一样的用于窃笑的 SDK?提前致谢

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

推荐答案

首先你需要在 twitter 上创建一个应用程序

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.

这篇关于如何在android中将图像发布到推特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆