【问题标题】:How to upload Image to twitter using update_with_media twitter api in android?如何在 android 中使用 update_with_media twitter api 将图像上传到 twitter?
【发布时间】:2013-02-26 13:10:29
【问题描述】:
https://api.twitter.com/1.1/statuses/update_with_media.json

在对如何在twitter上发布图片进行了大量研究之后,我得到了这个url来发布图片到twitter。但是我不知道如何使用它以及我需要传递什么参数。

我也发现了

1) 发布到 Twitpic 是向 twitter 发布图像的一种方式,但我不知道如何使用该 twitpic 库。

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

提前致谢

【问题讨论】:

    标签: android


    【解决方案1】:

    检查下面的代码:你必须使用twitter4j-core-2.1.11.jar & twitpic4j.jar

    在使用此checkthispost 之前。

    使用上面的安卓代码登录推特。

    您必须登录推特并在此方法中使用OAUTH_TOKENOAUTH_TOKEN_SECRET。在这个我已经通过URL同样的方式你也可以通过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

    对于位图,您可以像这样使用:upload.upload(String, inputstream);

    Edited

    我已检查我的代码并将twitter4j-core-2.1.11.jar 替换为twitter4j-core-3.0.3.jar

    查看完整代码here

    并在https://dev.twitter.comhttps://dev.twitter.com上更改 Twitter 应用中的一些设置

    它工作正常....

    【讨论】:

    • 我的 twitter4j 2.2.5 jar 不包含你在这个类中使用过的类,我已经试过了。
    • 使用 twitter4j-core-2.1.11.jar & twitpic4j.jar 来执行这段代码。
    • 我也有这个 jar 文件 twitter4j-core-2.1.11.jar,但它现在不工作。我确定因为我现在已经使用了这个 jar 文件。它在 2 周前工作但它没有现在工作。
    • 正确检查日志它会给你一些例外。你在安卓设备或模拟器中检查过这个吗??
    • oauth.signpost.exception.OAuthCommunicationException:与服务提供商的通信失败:服务提供商响应错误:301(永久移动)
    【解决方案2】:

    看看这个教程它解决了我的整个问题 Twit image along text

    【讨论】:

    • 什么类型的患者?
    猜你喜欢
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 2020-11-04
    • 2015-01-10
    • 2021-04-27
    • 1970-01-01
    相关资源
    最近更新 更多