public override string ShortenURL(string url) { if (!string.IsNullOrEmpty(url)) { string query; switch (UploadMethod) { default: case AccountType.Anonymous: query = string.Format("{0}?key={1}", APIURL, AnonymousKey); break; case AccountType.User: query = OAuthManager.GenerateQuery(APIURL, null, HttpMethod.Post, AuthInfo); break; } string json = string.Format("{{\"longUrl\":\"{0}\"}}", url); string response = SendPostRequestJSON(query, json); if (!string.IsNullOrEmpty(response)) { GoogleURLShortenerResponse result = JsonConvert.DeserializeObject <GoogleURLShortenerResponse>(response); if (result != null) { return(result.id); } } } return(null); }
public override UploadResult ShortenURL(string url) { UploadResult result = new UploadResult { URL = url }; if (!string.IsNullOrEmpty(url)) { string query; switch (UploadMethod) { default: case AccountType.Anonymous: query = string.Format("https://www.googleapis.com/urlshortener/v1/url?key={0}", AnonymousKey); break; case AccountType.User: if (!CheckAuthorization()) { return(null); } query = string.Format("https://www.googleapis.com/urlshortener/v1/url?access_token={0}", AuthInfo.Token.access_token); break; } string json = string.Format("{{\"longUrl\":\"{0}\"}}", url); result.Response = SendPostRequestJSON(query, json); if (!string.IsNullOrEmpty(result.Response)) { GoogleURLShortenerResponse response = JsonConvert.DeserializeObject <GoogleURLShortenerResponse>(result.Response); if (response != null) { result.ShortenedURL = response.id; } } } return(result); }