public static List<Task<string>> DownloadAllJsonAsync(this IEnumerable<string> urls, TwitterAuth twitterAuth) { if (twitterAuth == null) return urls.DownloadAllAsync(ContentType.Json); return urls.DownloadAllAsync(ContentType.Json, (webReq, uri) => { if (twitterAuth.AccessToken != null) { webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest( twitterAuth.OAuthProvider, twitterAuth.AccessToken, twitterAuth.AccessTokenSecret, HttpMethod.Get, uri, null); } }); }
public static string DownloadJsonFromUrl(this string url, TwitterAuth twitterAuth) { if (twitterAuth == null) return url.DownloadJsonFromUrl(); var uri = new Uri(url); var webReq = (HttpWebRequest)WebRequest.Create(uri); webReq.Accept = ContentType.Json; if (twitterAuth.AccessToken != null) { webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest( twitterAuth.OAuthProvider, twitterAuth.AccessToken, twitterAuth.AccessTokenSecret, HttpMethod.Get, uri, null); } using (var webRes = webReq.GetResponse()) return webRes.DownloadText(); }