我遇到 TweetInvi 0.9.9.7 无法上传视频的问题。该视频是 9MB MP4 视频,我可以使用网络界面将其上传到 Twitter。 我收到的错误消息是:
The tweet cannot be published as some of the medias could not be published!
我使用 fiddler 可以看到此错误消息从 API 返回:
error=segment size must be <= 1.
根据一位开发人员的说法,当超过 5MB 的视频尝试上传到 Twitter 但没有分块发送时,就会出现该错误。 https://twittercommunity.com/t/append-call-in-video-upload-api-giving-error/49067
这是我的代码,我做错了什么吗?上传 5MB 以下的文件工作正常,但 official API spec supports video up to 15MB
Auth.ApplicationCredentials = new TwitterCredentials("blahblahblah", "censoring private key", "***private, keep out***", "***beware of dog***");
var binary = File.ReadAllBytes(VideoPath);
Tweet.PublishTweetWithVideo("Here is some tweet text", binary);
最佳答案
最终,我发现了这种未记录的美丽:
Upload.CreateChunkedUploader();
这准确地公开了我上传这个较大文件所需的功能。这是我的新工作代码,供可能遇到此问题的其他人使用。
var chunk = Upload.CreateChunkedUploader(); //Create an instance of the ChunkedUploader class (I believe this is the only way to get this object)
using(FileStream fs = File.OpenRead(VideoPath))
{
chunk.Init("video/mp4", (int)fs.Length); //Important! When initialized correctly, your "chunk" object will now have a type long "MediaId"
byte[] buffer = new byte[4900000]; //Your chunk MUST be 5MB or less or else the Append function will fail silently.
int bytesRead = 0;
while((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
byte[] copy = new byte[bytesRead];
Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead);
chunk.Append(copy, chunk.NextSegmentIndex); //The library says the NextSegment Parameter is optional, however I wasn't able to get it to work if I left it out.
}
}
var video = chunk.Complete(); //This tells the API that we are done uploading.
Tweet.PublishTweet("Tweet text:", new PublishTweetOptionalParameters()
{
Medias = new List<IMedia>() { video }
});
从中得出的重要结论:
- 如果不先将大于 5MB 的文件分开,您就无法上传这些文件。
- TweetInvi 已经有一个机制来处理这个限制,我只是找不到任何相关文档。
- API 的硬限制为每个视频文件 15MB。 Despite twitter's support site which claims it can handle up to 512MB
Note: You’ll be prompted if the selected video is not in a supported format. Maximum file size is 512MB. See here for more details about formats.
关于c# - TweetInvi 视频上传失败,错误代码 "The tweet cannot be published as some of the medias could not be published!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33049234/