2

我遇到了 TweetInvi 0.9.9.7 无法上传视频的问题。该视频是一个 9MB MP4 视频,我可以使用 Web 界面将其上传到 Twitter。我得到的错误信息是:

该推文无法发布,因为某些媒体无法发布!

我使用 fiddler 可以看到此错误消息从 API 返回:

错误=段大小必须 <= 1。

根据其中一位开发人员的说法,当超过 5MB 的视频试图上传到 Twitter 并且没有以块的形式发送时,就会发生该错误。 https://twittercommunity.com/t/append-call-in-video-upload-api-giving-error/49067

这是我的代码,我做错了吗?上传 5MB 以下的文件可以正常工作,但官方 API 规范支持最大 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);
4

1 回答 1

2

最终,我发现了这种无证之美: 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 }
        });

重要的收获:

注意:如果所选视频的格式不受支持,系统会提示您。最大文件大小为 512MB。有关格式的更多详细信息,请参见此处。

于 2015-10-10T08:27:11.237 回答