-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitterV2.js
More file actions
executable file
·93 lines (63 loc) · 1.95 KB
/
twitterV2.js
File metadata and controls
executable file
·93 lines (63 loc) · 1.95 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var Twit = require('twit');
var twit = new Twit({
consumer_key: 'WHyRO7p3gQmMST2Qqah4oR3Zz',
consumer_secret: '30uAt79YAIIO7wG05I10bX1lDOIfhvvV0HgAglt9Ck1N1nvr5b',
access_token: '2881725773-FyOJltDuROXKhUTA4fa2qew699Sb6j9y2zYsnFl',
access_token_secret: 'BpxKUrYsKG38tmqZAfHhaM4gBpaNahK7LN0h8S6nHViSz'
});
var twittr = (function(){
/*
text = data.statuses[element].text;
data.entities.hashtags[0]
//
// filter the public stream by the latitude/longitude bounded box of San Francisco
//
var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ]
var stream = T.stream('statuses/filter', { locations: sanFrancisco })
stream.on('tweet', function (tweet) {
console.log(tweet)
})
*/
function search(tag, callback){
var text;
var hashTags = [];
twit.get('search/tweets', {q: tag, count: 5}, function(err, data, res){
if (data.statuses[0] !== undefined)
{
text = data.statuses[0].text;
for (var i = 0; i < 5; i++)
{
var tweet = data.statuses[i];
if (tweet.entities.hashtags.length > 0)
hashTags.push(tweet.entities.hashtags[0]);
}
callback(text, hashTags);
}
});
}
function geoSearch(tag, lat, lon, mlat, mlon, callback){
var area = [lat, lon, mlat, mlon];
var stream = twit.stream('statuses/filter', { locations: area });
stream.on('tweet', function (tweet) {
//console.log(tweet)
})
// stream should be set now. Go geolocating
}
function since(tag, date, callback){
var d = tag + " since:" + date;
twit.get('search/tweets', { q: d, count: 1 }, function(err, data, response) {
if (data.statuses[0] !== undefined)
{
var text = data.statuses[0].text;
console.log("Tweet found from since method.");
callback(text);
}
})
}
return{
search: search,
geosearch: geoSearch,
since: since,
}
}());
module.exports = twittr;