Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API attitude operator doesn't work

I have been using Twitters search API (via the node-twitter module) and I am running into an issue with the attitude operator. I am looking to get both positive and negative tweets about a certain subject. Currently though they return identical results. Here is my code that calls the API.

// Add since ID for future requests
twitterSearchClient.search(
    {'q'          :'xmas+%3A%28',
     'lang'       : 'en',
     'count'      : 100,
     'result_type': 'recent'},
    function(error, result) {
        if (error) {
            console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
        }

        if (result) {
            var requestDetails = result.search_metadata;
            var results = result.statuses;
            var resultsLength = results.length;
            var r;
            var data;
            var d;

            console.log(resultsLength);

            for (var i=0; i<resultsLength; i++) {

               console.log(r.text);
            }   
        }
    }
);

As you can see I am using the fully urlencoded value like the example in the documentation. I have also tried using xmas+%3A) for positive and xmas+%3A( for negative but this returns a 401 unauthorised error for some reason.

Has anyone ran into this issue or has a solution.

If you have any future questions I will be happy to answer them

Thanks in advance.

like image 979
David Jones Avatar asked Nov 01 '22 12:11

David Jones


2 Answers

Per twitter's docs

Please, make sure to URL encode these queries before making the request

When going to that url and typing in your search xmas :) I got this query

https://twitter.com/search?q=xmas%20%3A)

as you can see xmas :) = xmas%20%3A) and xmas :( ends up being

https://twitter.com/search?q=xmas%20%3A(

xmas :( = xmas%20%3A(

If you still do not get different results (you can compare the results to what get when doing the search on the link above) then it is not the query, but maybe how you are making the call. Will need additional information if that is the case.

like image 108
gmaniac Avatar answered Nov 15 '22 13:11

gmaniac


In this case, have you tried not encoding your query? The client may well be encoding it on your behalf.

...
'q': 'xmas :(',
...

NOTE: You do not mention, or link to which twitter client (via npm?) that you are using.


I can't speak for your specific issues, when I search via the form on the site I do get different results, and the queries are URI encoded... When you are passing input to a remote query string, I would recommend using encodeURIComponent('xmas :)') for your input values, this will yield the most predictable results.

like image 41
Tracker1 Avatar answered Nov 15 '22 11:11

Tracker1