在https://stream.twitter.com/1.1/statuses/filter.json上未经授权的401

时间:2016-08-10 12:04:56

标签: c# twitter stream dotnet-httpclient

我只在位置过滤器上获得401 Unauthorized。跟踪和其他过滤器正常工作。我对请求使用OAuth1身份验证。

using (var client = new HttpClient(new OAuth1MessageHandler(new HttpClientHandler(), "oauthkey", "oauthsecret", "oauthToken", "oauthTokenSecret", "",OAuthRequestType.ForAccessToken)))

        {
            client.BaseAddress = new Uri("https://stream.twitter.com/1.1/");
            client.DefaultRequestHeaders.Accept.Clear();
            //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Accept
                .Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
            client.Timeout = TimeSpan.FromMinutes(5);
            var locations = HttpUtility.UrlEncode("locations=-122.75,36.8,-121.75,37.8");
            var request = new HttpRequestMessage(HttpMethod.Get, "statuses/filter.json?"+ locations);

            var response = await client.SendAsync(request,HttpCompletionOption.ResponseHeadersRead);
            var stream = await response.Content.ReadAsStreamAsync();
            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    Console.WriteLine(reader.ReadLine());
                }
            }
        }

0 个答案:

没有答案