/// <summary>
 /// Posts a photo inline during a request to a given provider, before making an API call to Twitter.
 /// This method should only be used with updating status, retweeting, or sending direct messages,
 /// as the new photo's URL is injected in the outgoing message; otherwise, the photo is posted but 
 /// the URL is lost.
 /// </summary>
 /// <param name="instance">The current query expression</param>
 /// <param name="path">A path to the image</param>
 /// <param name="provider">A photo posting service provider</param>
 /// <returns>The current query expression</returns>
 public static IFluentTwitter PostPhoto(this ITwitterPhotos instance, string path,
                                        SendPhotoServiceProvider provider)
 {
     instance.Root.Parameters.PostImageProvider = provider;
     instance.Root.Parameters.PostImagePath = path;
     return instance.Root;
 }
        public static string SendPhoto(WebQueryBase query, SendPhotoServiceProvider provider, ImageFormat format, string path, string username, string password)
        {
            string response;
            switch (provider)
            {
                case SendPhotoServiceProvider.TwitPic:
                    // http://twitpic.com/api.do
                    response = SendPhoto(format, query, path, "http://twitpic.com/api/upload", username, password);
                    break;
                case SendPhotoServiceProvider.YFrog:
                    // http://yfrog.com/upload_and_post.html
                    response = SendPhoto(format, query, path, "http://yfrog.com/api/upload", username, password);
                    break;
                case SendPhotoServiceProvider.TwitGoo:
                    // http://twitgoo.com/upload_and_post.html
                    response = SendPhoto(format, query, path, "http://twitgoo.com/api/upload", username, password);
                    break;
                default:
                    throw new NotSupportedException("Unknown photo service provider specified");
            }

            if (!response.Contains("mediaurl"))
            {
                return null;
            }

            var match = Regex.Match(response, "<mediaurl[^>]*>(.*?)</mediaurl>");
            var mediaUrl = XElement.Parse(match.Value).Value;

            return mediaUrl;
        }