https://api.twitter.com/1.1/statuses/update_with_media.json
在对如何在 twitter 上发布图片进行了大量研究之后,我得到了这个用于将图片发布到 twitter 的 url。但是我不知道如何使用它以及我需要传递哪些参数。
我也发现了
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
提前致谢
最佳答案
检查下面的代码:你必须使用 twitter4j-core-2.1.11.jar
& twitpic4j.jar
使用前 checkthispost .
使用上面的android代码登录到twitter。
您必须登录 Twitter 并在此方法中使用 OAUTH_TOKEN
和 OAUTH_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);
已编辑
我检查了我的代码并将 twitter4j-core-2.1.11.jar
替换为 twitter4j-core-3.0.3.jar
查看完整代码 here
并在 https://dev.twitter.com 上更改 Twitter 应用程序中的一些设置|
它工作正常....
关于android - 如何在 android 中使用 update_with_media twitter api 将图片上传到 twitter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15089971/