2

I am trying to send a tweet with video but getting following error in the "await twitterCtx.TweetWithMediaAsync" line

Error creating status.

        if (Request.Params["VideoId"] != "")
        {
            AspNetAuthorizer auth = (AspNetAuthorizer)Session["TW"];

            var twitterCtx = new TwitterContext(auth);

            string status = "Testing TweetWithMedia #Linq2Twitter £ " + DateTime.Now.ToString(CultureInfo.InvariantCulture);
            const bool PossiblySensitive = false;
            const decimal Latitude = TwitterContext.NoCoordinate;
            const decimal Longitude = TwitterContext.NoCoordinate;
            const bool DisplayCoordinates = false;
            const string PlaceID = null;
            string ReplaceThisWithYourImageLocation = @"c:\foo\foo\" + Request.Params["VideoId"] + ".mp4";

            byte[] imageBytes = File.ReadAllBytes(ReplaceThisWithYourImageLocation);

            Status tweet = await twitterCtx.TweetWithMediaAsync(
                status, PossiblySensitive, Latitude, Longitude,
                PlaceID, DisplayCoordinates, imageBytes);

        }

video size ~3MB

Mert
  • 6,432
  • 6
  • 32
  • 68

3 Answers3

2

The Twitter API only supports uploading images. Also, TweetWithMediaAsync (=Twitter API statuses\update_with_media endpoint) is deprecated and replaced with UploadMediaAsync (=Twitter API media\upload endpoint).

You can download LINQ to Twitter source code for a demo and read my blog post, Uploading Multiple Images in Parallel with Async and LINQ to Twitter, for more info.

Update

Please see @Jagadeesh Govindaraj answer as Video uploads are a new capability that is now available.

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
1

Is now posible to upload Videos in Twitter

priavte async Task UploadVideoAsync(TwitterContext twitterCtx)
{
                var additionalOwners = new List<ulong> { 3265644348, 15411837 };
                string status =
                    "Testing video upload tweet #Linq2Twitter £ " +
                    DateTime.Now.ToString(CultureInfo.InvariantCulture);

                var media = await twitterCtx.UploadMediaAsync(
                    File.ReadAllBytes(@"..\..\images\SampleVideo.mp4"), "video/mp4");

                Status tweet = await twitterCtx.TweetAsync(status, new ulong[] { media.MediaID });

                if (tweet != null)
                    Console.WriteLine("Tweet sent: " + tweet.Text);
}

**Note :**Code from orginal Samples in LinqtoTwitter

Jagadeesh Govindaraj
  • 6,977
  • 6
  • 32
  • 52
0

It is supporting now. But i can not success with UploadMediaAsync :) The second param is not mime type, it is cancellation token, so twitter can not recognize my mp4 file ;)

rbostan
  • 37
  • 5