-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtwitter.js
75 lines (62 loc) · 2.13 KB
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var Twitter = require('twitter');
var client = new Twitter(
{
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: '',
});
/* search user */
client.get('users/lookup',{screen_name: 'narendramodi ',count: 10}, function(err,data,response){
const tweets = data;
// const tweets = data.statuses[].text;
console.log(tweets);
})
// Muted users list
client.get('mutes/users/list', function(error, tweets, response) {
if(error) throw error;
//console.log(tweets.users);
var tu= tweets.users.length;
var i;
for(i=0;i<tweets.users.length;i++)
{
console.log(tweets.users[i]['name']);
}
//console.log(tweets.users[1]['name']);
//console.log(response); // Raw response object.
});
// to tweet
client.post('statuses/update', {status: 'tweet sample using API'}, function(error, tweet, response)
{
if(error) throw error;
console.log(tweet); // Tweet body.
//console.log(response); // Raw response object.
});
//follow a friend with specific id or screen_name
client.post('friendships/create', {screen_name : "prernagupta"}, function(error, tweet, response) {
if(error) throw error;
console.log(tweet); // Tweet body.
//console.log(response); // Raw response object.
});
//following someone's followers
client.get('followers/ids', {screen_name:"jayachandra116",count:10},function(error, tweets, response) {
if(error) throw error;
//console.log(tweets);
var i;
for (i=0;i<tweets['ids'].length;i++)
{
if (tweets['ids'][i].length == 19)
{
client.post('friendships/create', {user_id : tweets['ids'][i]}, function(error, tweet, response) {
if(error) throw error;
//console.log(response); // Raw response object.
console.log(`successfully followed : ${tweets['ids'][i]} `) // Tweet body.
});
}
}
});
//following a particular person using screen name
client.post('friendships/create', {screen_name:"elonmusk"}, function(error, tweet, response) {
if(error) throw error;
console.log(tweet)
})