This project has moved. For the latest updates, please go here.

Post picture in twitter :

Sep 3, 2012 at 1:29 AM


I tried this code to post a picture in twitter its work fine when the url of the picture is local like: c:/....

But if i use an url like: 

or if i use Bitly to shorten the url . doesn't work 

Data = Utilities.GetFileBytes(...) doesn't accepte a formal url lik: http.....


static void TweetWithMediaDemo(TwitterContext twitterCtx)
string status = "Testing TweetWithMedia #Linq2Twitter " + DateTime.Now.ToString(CultureInfo.InvariantCulture);
const bool possiblySensitive = false;
const decimal latitude = StatusExtensions.NoCoordinate; //37.78215m;
const decimal longitude = StatusExtensions.NoCoordinate; // -122.40060m;
const bool displayCoordinates = false;

const string replaceThisWithYourImageLocation = @"..\..\images\200xColor_2.png";

var mediaItems =
new List<Media>
new Media
Data = Utilities.GetFileBytes(replaceThisWithYourImageLocation),
FileName = "200xColor_2.png",
ContentType = MediaContentType.Png

Status tweet = twitterCtx.TweetWithMedia(
, possiblySensitive, latitude, longitude,
null, displayCoordinates, mediaItems, null);

Console.WriteLine("Media item sent - Tweet Text: " + tweet.Text);

I'm sorry for my bad englaish,


Sep 3, 2012 at 4:46 AM


The GetFileBytes is a utility method I included for the demo. It returns a byte[] of the image, which I assign to the Data property of the Media instance. To achieve your goal, you can write your own method that retrieves the image the way you want and convert that image to a byte[].  Then assign the byte[] to the Data property as I've done.