-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.js
72 lines (60 loc) · 1.6 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
// twitter.js
var module = require('node-twitter-api');
var api;
var callbacks = {};
var tokens = {};
var timeout = 30000;
var getRequestToken;
exports.getActions = function(addAction){
}
exports.test = function(consumer_key, consumer_secret, callback_url, callback){
if(consumer_key != null && consumer_secret != null && callback_url != null){
var conf = {
"consumerKey": consumer_key,
"consumerSecret": consumer_secret,
"callback": callback_url+"/"
}
var test = new module(conf);
test.getRequestToken(function(err, request_token, request_token_secret, request_token, results){
if(err){
callback(false);
}else{
callback(true);
}
});
}else{
callback(false);
}
}
exports.setupAPI = function(consumer_key, consumer_secret, callback_url){
tokens = {
"consumerKey": consumer_key,
"consumerSecret": consumer_secret,
"callback": callback_url+"/"
}
api = new module(tokens);
}
exports.getUserToken = function (socket, callback){
api.getRequestToken(function(error, request_token, request_token_secret, results){
if (error) {
console.log(error);
callback(false);
} else {
socket.emit('openTwitterAuthPage', {"request_token" : request_token});
callbacks['receiveTokens'] = callback;
setTimeout(function(){
console.log('Twitter time out');
if(callbacks['receiveTokens'] != null){
callbacks['receiveTokens'](false);
socket.emit('closeTwitterAuthPage', {});
}
}, timeout);
}
});
}
exports.receiveTokens = function(req){
console.log(req);
callbacks['receiveTokens'](true);
callbacks['receiveTokens'] = null;
// LOT OF WORK TODO HERE
}