'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:count
since_id
max_id
trim_user
contributor_details
include_entities
callback
- 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_id
count
max_id
trim_user
exclude_replies
contributor_details
include_rts
callback
- 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:count
since_id
max_id
trim_user
exclude_replies
contributor_details
include_entities
callback
- 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:count
since_id
max_id
trim_user
include_entities
include_user_entities
callback
- 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;