Вопрос

Hi I have an app that uses /1.1/search/tweets.json.

I am doing a request with this parameters:

query = "Hello World" count = 100

private static object MakeRequest(NameValueCollection parameters)
        {
            var client = new RestClient("https://api.twitter.com")
            {
                Authenticator = OAuth1Authenticator.ForProtectedResource(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, SECRET_ACCESS_TOKEN)
            };

            var request = new RestRequest("/1.1/search/tweets.json", Method.GET);
            foreach (string key in parameters)
            {

                request.AddParameter(key, HttpUtility.UrlEncode(parameters[key]));
            }

            var response = client.Execute(request);
            return JsonConvert.DeserializeObject(response.Content);


        }

It works fine the first time, but if the query have more than 100 twits the "could not authenticate you" message appears.

What may be wrong?

Это было полезно?

Решение

After some debugging I found the issue.

The main problem is that HttpUtility.UrlEncode() transforms "Hello World" to "Hello+World", and if we have more than 100 twits the query that comes back from the request is "Hello%2bWorld".Transform that to "Hello+World" and everything comes ok.

So basically you have to be very careful with the URL Encoding.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top