예제 #1
0
        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;
        }
예제 #2
0
        public static string SendPhoto(ImageFormat format, WebQueryBase query, string path, string url, string username, string password)
        {
            var contentType = format.ToContentType();

            var mediaParameter = HttpPostParameter.CreateFile("media", "photo", path, contentType);
            var usernameParameter = new HttpPostParameter("username", username);
            var passwordParameter = new HttpPostParameter("password", password);

            var parameters = new[] { mediaParameter, usernameParameter, passwordParameter };

            return query.Request(url, parameters);
        }