Post picture in twitter :

Sep 3, 2012 at 1:29 AM

Hi,

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: http://anecdoclick.centerblog.net/voir-photo?u=http://anecdoclick.a.n.pic.centerblog.net/9nnprjdm.jpg 

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(
            status
, possiblySensitive, latitude, longitude,
           
null, displayCoordinates, mediaItems, null);

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

I'm sorry for my bad englaish,

thanks, 

Coordinator
Sep 3, 2012 at 4:46 AM

Hi,

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.

Joe