问题描述
限时送ChatGPT账号..我必须从我的 Java 应用程序将视频上传到 Twitter(发布带有视频的推文文本).我使用 twitter4j 上传图片,效果很好.我对上传视频的最佳方式感到困惑.我在这个链接中找到了 https://github/mrisney/twitter-java-ads-sdk/blob/master/src/examples/VideoUploadExample.java 实现twurl 命令,但我想知道是否可以使用 twitter4j 上传视频就像我为图像所做的那样?或者我必须使用 twurl 的方式来做到这一点?有没有可能直接在推特上发布视频?
I have to upload video to twitter (post a tweet text with video) from my java application. I use twitter4j to upload images and it works perfectly. I'm confused about the best way to upload video. I have found in this link https://github/mrisney/twitter-java-ads-sdk/blob/master/src/examples/VideoUploadExample.java the code that implements the twurl command but I want to know if it's possible to upload video with twitter4j like I have done for the image? Or have I to use the twurl way to do it? And is there any possibility to post video directely on twitter?
这就是我为图片上传所做的
This is what I do for the image upload
` Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
AccessToken accessToken = new AccessToken(accessTokenStr,
accessTokenSecret);
twitter.setOAuthAccessToken(accessToken);
StatusUpdate statusUpdate = new StatusUpdate(text);
statusUpdate.setMedia("New pic", new URL(photo).openStream());
twitter.updateStatus(statusUpdate.inReplyToStatusId(tweetId));`
谢谢
推荐答案
使用 uploadMediaChunked
发送视频,获取媒体 ID,然后在您的媒体上使用 setMediaId
.
Send the video with uploadMediaChunked
, get the media ID and then use setMediaId
on your media.
示例(Kotlin):
val status = StatusUpdate("Hello, World!")
val mediaChunked = twitter.uploadMediaChunked("file_name.mp4", File(assetsFolder, "file_name.mp4").inputStream())
status.setMediaIds(mediaChunked.mediaId)
您需要使用uploadMediaChunked
,如果您使用uploadMedia
Twitter 将拒绝您的状态/媒体!
You need to use uploadMediaChunked
, if you use uploadMedia
Twitter will reject your status/media!
这篇关于在推特上上传视频的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论