【问题标题】:TweetInvi Video Upload Failing With "The tweet cannot be published as some of the medias could not be published!"TweetInvi 视频上传失败,显示“无法发布推文,因为某些媒体无法发布!”
【发布时间】:2016-01-08 01:11:41
【问题描述】:

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

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

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

错误=段大小必须为

根据其中一位开发人员的说法,当超过 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);

【问题讨论】:

    标签: c# .net twitter tweetinvi


    【解决方案1】:

    最终,我发现了这种无证之美: 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。有关更多详细信息,请参见此处 格式。

    【讨论】:

    • 很高兴你找到了这个。如果您有任何建议,请随时在 github 上发布,我会尽我所能改进库。
    • 嘿,谢谢!会做!你的图书馆太棒了。我非常依赖它,但这是我遇到的第一个也是唯一一个障碍,最终,你的图书馆已经处理了它。我只是需要更加努力地寻找它。
    猜你喜欢
    • 2021-08-03
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 2018-05-07
    • 2016-06-12
    相关资源
    最近更新 更多