如何上传图片在Android中使用update_with_media Twitter的API来Twitter? [英] How to upload Image to twitter using update_with_media twitter api in android?

查看:134
本文介绍了如何上传图片在Android中使用update_with_media Twitter的API来Twitter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

做了很多关于如何发布在Twitter上的图像的研究后,我得到了这个网址张贴图像twitter.But我不知道如何利用这一点,我需要通过什么样的参数。

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.

我还发现,

1)张贴到Twitpic是张贴图片到Twitter的方式之一,但我不知道如何使用twitpic库。

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.

请建议我在使用上述API

please suggest me in using the above api

在此先感谢

推荐答案

检查以下code:你必须使用使用 twitter4j核-2.1.11.jar &安培; twitpic4j.jar

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

使用在此之前 checkthispost

在登录使用更高版本的Andr​​oid code到Twitter。

Login in to twitter using above android code.

您必须拥有Twitter的登录并使用组oauth_token &安培; OAUTH_TOKEN_SECRET 在此方法。在这我已经通过了网​​址相同的方式,也可以通过位图

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("http://i.stack.imgur.com/wz0qZ.jpg").openStream(),
                        "some text");
            
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

网​​址是给你上传的图片的URL

url is give you URL of uploaded image

为位图,您可以使用这样的: upload.upload(字符串,InputStream的);

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

编辑

Edited

我已经检查了我的code和替换 twitter4j核-2.1.11.jar twitter4j核心-3.0.3。 JAR

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

检查满code rel=\"nofollow\">

check full code here

,改变在Twitter的应用程序在 https://dev.twitter.com

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

其做工精细....

这篇关于如何上传图片在Android中使用update_with_media Twitter的API来Twitter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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