ntwitter icon indicating copy to clipboard operation
ntwitter copied to clipboard

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

Open databasedude opened this issue 12 years ago • 5 comments

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."

databasedude avatar Jun 12 '13 13:06 databasedude

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 avatar Jun 17 '13 12:06 sebhildebrandt

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

sebhildebrandt avatar Jun 17 '13 12:06 sebhildebrandt

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;
}

SamVerschueren avatar Jun 17 '13 14:06 SamVerschueren

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

technicalpickles avatar Jun 18 '13 17:06 technicalpickles

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

j127 avatar Oct 28 '13 05:10 j127