2017-06-01 41 views
0

我試圖文件上傳與tweetinvi.File上傳工作,爲圖像,但相同的代碼沒有顯示視頻(大型視頻超過20 MB)tweetinvi分塊上傳大量上載

我在這裏問,但現在answear

TweetInvi Large Video Upload Failing With Null Reference

,所以我另找solution.There是tweetinvi分塊上傳 我這個編碼,但它不工作,不給錯誤,但它不工作

if (file.ContentType.Contains("video"))//video 
         { 

          var video1 = System.IO.File.ReadAllBytes(path); 
          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 = System.IO.File.OpenRead(path)) 
          { 
           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[video1.Length]; //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); 
            TimeSpan s = new TimeSpan(); 

            chunk.Append(copy, chunk.NextSegmentIndex.ToString()); //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. 
          listMedia.Add(video); 


         } 
+0

我會調查您的問題。我在https://github.com/linvi/tweetinvi/issues/528上的github網站上添加了這個問題 – Linvi

回答

0

我想說,在處理你的bug後,我能夠確定你遇到的問題。

問題是您沒有指定上傳的media_category

除此之外,您需要等待媒體由Twitter處理。

在Tweetinvi 2.1中,過程應該更容易。請使用以下代碼:

var binary = File.ReadAllBytes(@"video_path"); 
var media = Upload.UploadVideo(binary); 

// The upload is completed but it does not mean it succeeded! 
if (!media.HasBeenUploaded) 
{ 
    // Something went wrong during the upload. 
    // Please retry or check the video type/settings. 
    return; 
} 

// Just wait for Twitter to have processed the upload (RECOMMENDED) 
Upload.WaitForMediaProcessingToGetAllMetadata(media); 

// Now the media is ready to be used in a Tweet 
var tweet = Tweet.PublishTweet("hello", new PublishTweetOptionalParameters 
{ 
    Medias = { media } 
}); 

你可以閱讀更多關於更新文檔上傳:https://github.com/linvi/tweetinvi/wiki/Upload#upload-status-video

最後請注意上傳的進一步改進計劃版本2.2和2.3。

有一個偉大的一天,感謝您報告這個問題,

乾杯 Linvi