gpt4 book ai didi

c# - TweetInvi 视频上传失败,出现 "The tweet cannot be published as some of the medias could not be published!"

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:08 26 4
gpt4 key购买 nike

我遇到 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.C​​reateChunkedUploader();

它完全公开了我上传这个更大的文件所需的功能。这是我的新工作代码,适用于可能遇到此问题的任何其他人。

        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 }
});

重要的收获:

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/

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