According to Twitter’s research, a photo or video link in a tweet doubled or tripled the likelihood of a musician’s / producer’s / record label’s status update being retweeted.

Fortunately, tweeting with media isn’t much more complicated than making a plain-text tweet. All you need to do is upload your media ahead of your tweet, then reference the media IDs when posting your status update.

And once again, LinqToTwitter has deeply abstracted that entire process for us, making it a snap … provided we’re tweeting images.

In the meantime, it’s probably easiest to upload your video to YouTube or Vimeo, and tweet a link to that video; your video should be embedded by Twitter if it’s on YouTube or Vimeo.

You can include up to four images; or one video; or one animated GIF per tweet. For example, you can have a JPEG and a non-animated GIF in a tweet. Or one video. But not a JPEG, an animated GIF and a video; or a video and two JPEGs.

Images cannot be more than 5MB each.

LinqToTwitter will allow you to upload multiple images in parallel. This is good, bad and ugly.

Good, because it should take less time to upload all your pictures (assuming you have the sockets available to make multiple connections to the Twitter API, of course).

Bad, because that fact may make you lazy about saving your pictures to as small a file size as possible before uploading. Netiquette and common sense still rule here, make your media files as small as reasonable.

And ugly, thanks to the Twitter API, because you still need to wait for all your media to finish uploading before you can tweet your media.

It’s not immediately clear to me whether you are able to tweet with media that was previously uploaded to your account, or if you can tweet media that was uploaded by someone else’s account, using the media ids of those pictures / videos.

I can’t get it to work; but I may be doing it wrong.

Uploading Your Media

Building on the code we developed in Part 2 to store our Twitter credentials, and prepare a context so we can interact with the API …

For now, take it on faith that we are able to pass to the Twitter API a series of tasks to complete, have them take however long they take, and proceed with the rest of our code when they’re done. That’s what each block of code, above, does: Upload media to Twitter, and proceed with the program whenever those tasks are complete.

Aside On Non-Local Media Paths

This section talks about tweeting media that isn’t in your local filesystem. You can safely skip to the next section if you don’t need to know how to tweet media that isn’t on your computer.

Note that in the above code examples, I assume that the media you are uploading exists in your local filesystem.

However, all LinqToTwitter needs is a byte array of the media file in order to successfully upload it. So we can tweet from a Stream, from a file retrieved via a WebRequest, from the Bitmap class … in other words, if .NET can somehow address a media file, it can probably put it into a byte array; and if a media file is in a byte array, LinqToTwitter can upload it to Twitter.

Suppose, for example, what you want to do is tweet a photo that was uploaded to your website, which is hosted on a third-party server.

So don’t feel as though your images have to be local files in order to tweet them. If you can get it into a byte array, you can use it.

Adding Your Media To Your Tweet

With our media uploaded, we’re now ready to post our tweet and make reference to those uploaded files (or file).

The way we make reference to those files (or file) in LinqToTwitter is via a List of Media IDs. (The media IDs we get back from Twitter will be long, unsigned integers.)

After LinqToTwitter uploads our pictures, it receives back from Twitter an ID number for each of those files. We send back to Twitter those same ID numbers when posting a tweet, and it knows that we intend to include those pictures in our tweet.

If we uploaded a single file, all we need to do is create a List containing the MediaID from the uploaded file: