TweetInvi视频上传失败“由于某些媒体无法发布,因此无法发布推文!”

时间:2015-10-10 01:14:51

标签: c# .net twitter tweetinvi

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

  

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

我使用了fiddler,可以看到这个错误消息是从API返回的:

  

错误=段大小必须为< = 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);

1 个答案:

答案 0 :(得分: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。有关详细信息,请参见此处   格式。