コード例 #1
0
        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;
            webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                twitterAuth.OAuthProvider, twitterAuth.AccessToken, twitterAuth.AccessTokenSecret, HttpMethod.Get, uri, null);

            using (var webRes = webReq.GetResponse())
                return(webRes.DownloadText());
        }
コード例 #2
0
		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);
				}

			});
		}
コード例 #3
0
		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();
		}
コード例 #4
0
        public static List <Task <string> > DownloadAllJsonAsync(this IEnumerable <string> urls, TwitterAuth twitterAuth)
        {
            if (twitterAuth == null)
            {
                return(urls.DownloadAllAsync(MimeTypes.Json));
            }

            return(urls.DownloadAllAsync(MimeTypes.Json, (webReq, uri) =>
            {
                if (twitterAuth.AccessToken != null)
                {
                    webReq.Headers[HttpRequestHeader.Authorization] = OAuthAuthorizer.AuthorizeRequest(
                        twitterAuth.OAuthProvider, twitterAuth.AccessToken, twitterAuth.AccessTokenSecret, HttpMethods.Get, uri, null);
                }
            }));
        }