如何上传的形象和地位利用twitter4j叽叽喳喳 [英] How to upload image and status to twitter using twitter4j

查看:181
本文介绍了如何上传的形象和地位利用twitter4j叽叽喳喳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的Andr​​oid应用程序上传图片以及状态。

I want to upload an image as well as status through my android application.

到目前为止,我已经尝试了很多例子,但他们没有帮助。 (我已经有CONSUMER_KEY,CONSUMER_SECRET,TWITPIC_API_KEY,我能够从我的应用程序发布的状态,我只需要code上传的图片)。

So far I have tried many examples, but none of them helped. (I already have the CONSUMER_KEY,CONSUMER_SECRET,TWITPIC_API_KEY and I'm able to post the status from my application,I only need the code for uploading an image).

我怎么能这样做?

推荐答案

您需要使用ImageUpload类twitter4j。下面code描述文字图片上传一个典型的场景。

You need to use ImageUpload class in twitter4j. The below code describes a typical scenario for image upload with text.

    AccessToken accessToken = twitterSession.getAccessToken();
    ConfigurationBuilder conf = new ConfigurationBuilder();
    conf.setOAuthConsumerKey(twitter_consumer_key);
    conf.setOAuthConsumerSecret(twitter_secret_key);
    conf.setUseSSL(true);
    conf.setHttpReadTimeout(2400000);
    conf.setHttpStreamingReadTimeout(2400000);
    conf.setOAuthAccessToken(accessToken.getToken());
    conf.setOAuthAccessTokenSecret(accessToken.getTokenSecret());
    conf.setMediaProviderAPIKey(twitpic_api_key);
    Configuration configuration = conf.build();
    OAuthAuthorization auth = new OAuthAuthorization(configuration);
    ImageUpload uploader = new ImageUploadFactory(configuration)
    .getInstance(auth);

    File photo=new File("abc/myimage.png");
    String status="Checkout my new image";

    uploader.upload(photo,status);

这篇关于如何上传的形象和地位利用twitter4j叽叽喳喳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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