asp.nettwittertweetsharp

Tweetsharp Twitter API - post multiple images


The code below works and will post to Twitter, but will only ever post one image to the account, even if three images are sent.

These are only jpg or png files, not video or animated gifs.

Any ideas would be appreciated.

    Dim service = New TwitterService(key, secret)
    service.AuthenticateWith(token, tokenSecret)

    Dim opt As New SendTweetWithMediaOptions

    Dim images As New Dictionary(Of String, IO.Stream)
    Dim myStream As FileStream

    If Len(ImgName1) > 0 Then
        myStream = New FileStream(ImgName1, FileMode.Open)
        images.Add("1", myStream)
    End If
    If Len(ImgName2) > 0 Then
        myStream = New FileStream(ImgName2, FileMode.Open)
        images.Add("2", myStream)
    End If
    If Len(ImgName3) > 0 Then
        myStream = New FileStream(ImgName3, FileMode.Open)
        images.Add("3", myStream)
    End If

    opt.Status = TweetText
    opt.Images = images

    Dim TwitterStatus = service.SendTweetWithMedia(opt)

Solution

  • The API end point called by that TweetSharp method doesn't support multiple images (I don't think it ever did, but either way the current docs say no; https://dev.twitter.com/rest/reference/post/statuses/update_with_media).

    What you need to do is use the UploadMedia endpoint to upload the image and capture the id for each, then send a tweet with the list of ids.

    I'm not sure which variant of TweetSharp you're using. The official/original one has known bugs in the Nuget package, and while the source in the repo has those fixed it is lacking the newer API support.

    You could try TweetMoaSharp (mostly maintained by me), as I believe this supports the new end points (but it's been a while since I looked). There's also tweetsharp-alternative on Nuget and a few others floating around that might have support.