1

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

4

3 回答 3

3

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

这是在 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(); 

查看本教程以获取更多详细信息。

于 2013-12-17T11:42:54.130 回答
0

我认为您想在 Android 中实现共享意图。

用户“第二”的这个答案和代码示例看起来适用。

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");

share.putExtra(Intent.EXTRA_STREAM,
   Uri.parse("file:///sdcard/DCIM/Camera/myPic.jpg"));

startActivity(Intent.createChooser(share, "Share Image"));
于 2013-06-13T17:42:50.633 回答
0

您可以使用 Intent 在 Twitter 上发布图像,您可以从这里下载完整的源代码 下载完整的源代码

Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(“image/jpeg”);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, “Select”));
于 2015-06-24T16:17:19.740 回答