TweetInvi 视频上传失败 "The tweet cannot be published as some of the medias could not be published!"

TweetInvi Video Upload Failing With "The tweet cannot be published as some of the medias could not be published!"

我遇到 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 }
        });

重要的收获:

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.