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

标签 c# .net twitter tweetinvi

我遇到 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/

相关文章:

c# - 取消锁定 session 事件

c# - 打印预览 C# 中的居中图像

python - 使用基于字符串数组中元素的集合名称在 pymongo 中创建 MongoDB 集合

c# - 使用 Autofac 将所有使用 Attribute 注释为 IEnumerable<Type> 的类解析

c# - 将 byte[] 转换为显式结构的最简单方法

c# - 如何通过与单个 int 变量进行比较来过滤列表 <int>?

.net - 是否有可能使日期数据类型接受一个月的13和所有月份的30?

.net - .Net在哪里可以找到BinaryFormatter序列化格式的官方规范?

android - 从 Android 应用程序向流行的社交网络分享内容时,如何通过 [我的应用程序] 添加共享?

c# - 异步 Twitter 搜索