如何在Android中使用twitter4j库图片发布到Twitter [英] How to post picture to Twitter using twitter4j library in Android
本文介绍了如何在Android中使用twitter4j库图片发布到Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要上传图片到Twitter上我的应用程序。我用twitter4j库只发布文字。但我怎么也找不到张贴图片的文字。感谢您的帮助。
解决方案
- 要发布你必须使用Twitter4j媒体延伸,并与任一TwitPic或YFrog注册您的应用程序一个图像。
-
获取来自这些服务的关键和令牌,然后
/ *
*上传文件到twitPic并获得网址。然后追加这个网址到你的Twitter消息。
* /
公共静态字符串upload_twic_pic(档案文件)
抛出TwitterException {
字符串URL = NULL;
如果(文件!= NULL){
配置的conf =新ConfigurationBuilder()setMediaProviderAPIKey(TWITPIC_KEY).build();
ImageUpload上传=新ImageUploadFactory(CONF).getInstance(MediaProvider.PLIXI); //使用ImageUploadFactory
URL = upload.upload(文件);
}
返回URL;
I want to post image to twitter on my app. I use "twitter4j" library to post only text. But i cannot find how to post image with text. Thanks for help.
解决方案
- To post a image you have to use media extension of Twitter4j and register your app with either TwitPic or YFrog .
Get KEY and TOKEN from those services and then
/* * Upload File to twitPic and get url . Then append this url to your twitter message. */ public static String upload_twic_pic(File file) throws TwitterException { String url = null; if (file != null) { Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(TWITPIC_KEY).build(); ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.PLIXI); //Use ImageUploadFactory url = upload.upload(file); } return url;
这篇关于如何在Android中使用twitter4j库图片发布到Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文