gpt4 book ai didi

android - 推特。媒体发布状态

转载 作者:搜寻专家 更新时间:2023-11-01 09:07:41 26 4
gpt4 key购买 nike

是否可以使用 Scribe-Java 和 twitter POST Url“https://upload.twitter.com/1/statuses/update_with_media.json”上传图片?
my source
我收到回复:{"request": "\/1\/statuses\/update_with_media.json", "error": "Could not authenticate with OAuth."

最佳答案

只是为了帮助其他人看这个,构建多部分的一个简单方法是将 httpmime-4.0.1.jar 和 apache-mime4j-0.6.jar 添加到您的路径并执行以下操作。

        /* You will have done this bit earlier to authorize the user

OAuthService service = new ServiceBuilder().provider(TwitterApi.SSL.class).apiKey("[YOUR API KEY]").apiSecret("[YOUR SECRET]").callback("twitter://callback").build();
Token accessToken = Do you oauth authorization as normal

*/

OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json");
MultipartEntity entity = new MultipartEntity();
try {

entity.addPart("status", new StringBody("insert vacuous statement here"));
entity.addPart("media", new FileBody(new File("/path/of/your/image/file")));

ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);

request.addPayload(out.toByteArray());
request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());

service.signRequest(accessToken, request);
Response response = request.send();

if (response.isSuccessful()) {
// you're all good
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

这里的权衡当然是将 2 个 jar 的大小添加到您的 APK

关于android - 推特。媒体发布状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10686110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com