'use strict';Convenience methods for Timelines actions.
var TwitterLib = require('twitter-rest');
var timeline = new TwitterLib.Timelines(var_with_config);
timeline.mentions(params, callback);
timeline.user(params, callback);
timeline.home(params, callback);
timeline.retweets(params, callback);
uri - base URI’s to use (this should be provided by the library
itself)opts - Object with the user-provided paramsconsumer_key - requiredconsumer_secret - requiredtoken - requiredtoken_secret - requiredAn Object with methods mentions, user, home and retweets.
function Timelines(uri, opts) {
this.uri = uri;
this.opts = opts;
var tt = require('twitter-rest-lite');
this.api = tt.API(this.opts);
}This only works with oauth_token from the same user.
params - Object with params:countsince_idmax_idtrim_usercontributor_detailsinclude_entitiescallback - Callback FunctionReturns a callback with an Error object as first parameter if there was any
(otherwise just null) and an Array with tweets as second parameter.
var params = { count: 1 };
timeline.mentions(params, function (err, res) {
if (err)
throw err;
console.log(res);
});
Timelines.prototype.mentions = function(params, callback) {
var self = this;
if (params == null)
params = {};
self.api.get('/statuses/mentions_timeline.json', params, callback);
};params - Object with params:screen_name - [Required if user_id wasn’t provided]user_id - [Required if screen_name wasn’t provided]since_idcountmax_idtrim_userexclude_repliescontributor_detailsinclude_rtscallback - Callback FunctionReturns a callback with an Error object as first parameter if there was any
(otherwise just null) and an Array with tweets as second parameter.
timeline.user({
screen_name: 'random'
}, function (err, res) {
if (err)
throw err;
console.log(res);
});
Timelines.prototype.user = function(params, callback) {
var self = this;
if ((params.screen_name == null) && (params.user_id == null)) {
return callback(new Error(
'Twitter:Timelines.user requires either screen_name or user_id'
));
}
self.api.get('/statuses/user_timeline.json', params, callback);
};This only works with the oauth_token from the same user.
params - Object with params:countsince_idmax_idtrim_userexclude_repliescontributor_detailsinclude_entitiescallback - Callback FunctionReturns a callback with an Error object as first parameter if there was any
(otherwise just null) and an Array with tweets as second parameter.
timeline.home(null, function (err, res) {
if (err)
throw err;
console.log(res);
});
Timelines.prototype.home = function(params, callback) {
var self = this;
if (params == null)
params = {};
self.api.get('/statuses/home_timeline.json', params, callback);
};This only works with the oauth_token from the same user.
params - Object with params:countsince_idmax_idtrim_userinclude_entitiesinclude_user_entitiescallback - Callback FunctionReturns a callback with an Error object as first parameter if there was any
(otherwise just null) and an Array with tweets as second parameter.
timeline.retweets({}, function (err, response) {
if (err)
throw err;
console.log(response);
});
Timelines.prototype.retweets = function(params, callback) {
var self = this;
if (params == null)
params = {};
self.api.get('/statuses/retweets_of_me.json', params, callback);
};
module.exports = Timelines;