-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (66 loc) · 2.05 KB
/
Copy pathindex.js
File metadata and controls
72 lines (66 loc) · 2.05 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
var fs = require('fs');
var OAuth = require('oauth').OAuth;
exports.handler = function(event, context) {
var configJSON;
var config;
configJSON = fs.readFileSync('config.json', {encoding: 'utf-8'});
config = JSON.parse(configJSON);
if (!config) return context.fail('Failed to read configuration');
var oauth = new OAuth(
"https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token",
config.consumer_key,
config.consumer_secret,
"1.0",
config.callbackURI,
"HMAC-SHA1"
);
if (event.type == 'request_token') {
oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results) {
if (error) {
return context.fail(error);
}
else {
context.succeed({
token: oauth_token,
token_secret: oauth_token_secret
});
}
});
}
else if (event.type == 'auth_token') {
oauth.getOAuthAccessToken(
event.token,
event.token_secret,
event.verifier,
function(error, oauth_access_token, oauth_access_token_secret, results) {
if (error) {
return context.fail(error);
}
else {
context.succeed({
access_token: oauth_access_token,
access_token_secret: oauth_access_token_secret
});
}
}
);
}
else if (event.type == 'user_data') {
oauth.get(
"https://api.twitter.com/1.1/account/verify_credentials.json",
event.access_token, event.access_secret,
function(error, data) {
if(error) {
return context.fail("FAILURE: " + require('sys').inspect(error))
}
else {
context.succeed(data);
}
}
);
}
else {
return context.fail("type not recognized ( request_token or auth_token )");
}
};