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