When using TweetWithMedia, how do I set the media items paths on WP8.
Ideally I would just like to specifiy a web address for the .png is that possible?
If it has to be a local file, how to a specifiy the path? If I use "\ApplicationIcon.png" I get a "C:\ApplicationIcon.png" file not found error.
And if I try with a "ms-appdata:///ApplicationIcon.png" file path a different error.
Also, what relevance is the filename field of media element, it's that so if the picture is downloaded/saved from a client PC, it's given this fieldname?
I'm loving this API by the way!!
Oct 14, 2013 at 7:52 PM
I use the filename when making the HTTP Post to the Twitter API. When Twitter API introduced this particular endpoint, I didn't know if they would use filename or not, so I surfaced it to the developer, just in case. It turns out that they don't seem to use
the filename passed to them at all. The Status that you get back from the TweetWithMedia invocation contains an Entities property and you'll find a MediaEntity for the image you transmitted. They give the file it's own filename at a URL of their choice. So,
the short answer is that you can put anything into the filename that you want.
What you really want to pass is a byte of the image. Here's a sample (from the
docs for TweetWithMedia
string status = "Testing TweetWithMedia #Linq2Twitter £ " +
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 =
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);
Notice the MediaItems collection. As of today, you can only add one item to that collection, but I designed it like this to accommodate more if Twitter API ever decided to allow it. The Data property of the Media instance is the byte I was talking about.
Just get the image from wherever and serialize it into a byte. Notice that I included a utility in LINQ to Twitter that works with a normal file system path. However, you would have to write your own code if you're using some other type of resource or isolated