AvianFlu / ntwitter

Asynchronous Twitter REST/stream/search client API for node.js
https://github.com/AvianFlu/ntwitter
Other
784 stars 163 forks source link

No longer works. Must upgrade to Twitter API v.1.1 #110

Open databasedude opened 11 years ago

databasedude commented 11 years ago

This was working fine until yesterday around noon when Twitter shut off v.1. It now returns the following error: "The Twitter REST API v1 will soon stop functioning. Please migrate to API v1.1."

sebhildebrandt commented 11 years ago

To make "search" working again, I did the following:

in "keys.js", line 8, I corrected the search base to:

search_base: 'https://api.twitter.com/1.1/search', // old was 'http://search.twitter.com'

in "twitter.js", in line 166, I also corrected the search-URL

var url = this.options.search_base + '/tweets.json'; // old was 'search.json';

now it seems to work.

sebhildebrandt commented 11 years ago

... see updated fork at https://github.com/sebhildebrandt/ntwitter

SamVerschueren commented 11 years ago

This is my new search function that used the new API.

Twitter.prototype.search = function(q, params, callback) {
    if (typeof params === 'function') {
        callback = params;
        params = {};
     }

    if ( typeof callback !== 'function' ) {
        throw new Error('FAIL: INVALID CALLBACK.');
        return this;
    }

    var url = this.options.rest_base + '/search/tweets.json?q=' + q.replace('#', '%23') + '&' + querystring.stringify(params);

    var request = this.oauth.get(url, this.options.access_token_key, this.options.access_token_secret, function(error, data, response) {
        if ( error && error.statusCode ) {
            var err = new Error('HTTP Error ' + error.statusCode + ': ' + http.STATUS_CODES[error.statusCode]);
            err.statusCode = error.statusCode;
            err.data = error.data;

            callback(err);
        } 
        else if (error) {
            callback(error);
        }
        else {
            try {
                var json = JSON.parse(data);
            } 
            catch(err) {
                return callback(err);
            }

            callback(null, json);
        }
    });

    return this;
}
technicalpickles commented 11 years ago

@sebhildebrandt could you send out a pull request with those changes?

j127 commented 11 years ago

Doesn't work for me, even when changing lines 8 and 166.