5

I'm trying to get result from this query.

https://api.twitter.com/1.1/search/tweets.json?q=?&geocode=39.893280,32.779655,5km&count=100

I'm getting code:32 Could not authenticate you error. I'm using parse cloud code.

Parse.Cloud.httpRequest({
    method: 'GET',
    url: urlLink,
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization" : 'OAuth oauth_consumer_key="hKHVs8mDhW1rvZaPSLV9NywDS", oauth_nonce="5930fc59da48a2b30a5ff90939184b82", oauth_signature=somethingcorrect, oauth_signature_method="HMAC-SHA1", oauth_timestamp="1427745599", oauth_token="2900478017-RUQFnvSL7Vh1WohOBLbkswx55vtcgbnaexNt6ed", oauth_version="1.0"'
    },
    body: {
    },
    success: function(httpResponse) {
        // console.log(httpResponse.text);
        response.success(httpResponse.text);
    },
    error: function(httpResponse) {
        response.error('Request failed with response ' + httpResponse.status + ' , ' + JSON.stringify(httpResponse));
    }
});

I generated everything from here. So the keys and the signature is correct. Probably the urlLink I'm giving is in wrong format but I checked it a few times. What is wrong here?

Here is the curl code which works correct. Newlines are just for better readability.

curl --get 'https://api.twitter.com/1.1/search/tweets.json' 
--data 'count=100&geocode=39.893280%2C32.779655%2C5km&q=%3F' 
--header 'Authorization: OAuth oauth_consumer_key="hKHVs8mDhW1rvZaPSLV9NywDS", oauth_nonce="5930fc59da48a2b30a5ff90939184b82", oauth_signature=somethingcorrect, oauth_signature_method="HMAC-SHA1", oauth_timestamp="1427745599", oauth_token="2900478017-RUQFnvSL7Vh1WohOBLbkswx55vtcgbnaexNt6ed", oauth_version="1.0"' --verbose
Thellimist
  • 3,757
  • 5
  • 31
  • 49
  • What's with `q=?`? Shouldn't that be your search term? – Phil Mar 31 '15 at 00:39
  • search everything in the specified location. like SELECT * – Thellimist Mar 31 '15 at 08:34
  • Then it should be url encoded like it is in your curl request – Phil Mar 31 '15 at 20:09
  • I tried that but maybe I did something wrong can you provide an example? – Thellimist Mar 31 '15 at 20:17
  • Err, `q=%3F`, just like in your curl request – Phil Mar 31 '15 at 22:23
  • Thank you that was the problem. I thought I should also encode the ',' character. You can write the solution as an answer so I can accept it. It'll be easier for other people who have the same problem to solve it. My latest query is: https://api.twitter.com/1.1/search/tweets.json?q=%3F&geocode=39.893280,32.779655,5km&count=100 – Thellimist Mar 31 '15 at 22:29
  • 1
    It's more apt to close as a *"typo"*. FYI, you should pay close attention to the [documentation](https://dev.twitter.com/rest/reference/get/search/tweets) - *"**q**: A UTF-8, **URL-encoded** search query of 500 characters maximum, including operators"* – Phil Mar 31 '15 at 23:38

1 Answers1

6

The problem was instead of ? I should have wrote %3F

Here is the lastest version of the query

https://api.twitter.com/1.1/search/tweets.json?q=%3F&geocode=39.893280,32.779655,5km&count=100

Doc: https://dev.twitter.com/rest/reference/get/search/tweets

q: A UTF-8, URL-encoded search query of 500 characters maximum, including operators

Thellimist
  • 3,757
  • 5
  • 31
  • 49