-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (80 loc) · 2.46 KB
/
app.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* created by : @ichetandhembre
*/
var express = require('express')
, qs = require('querystring')
, request = require('request');
var app = express();
var array1 = [];
var appAccessToken;
// all environments
var port = process.env.PORT || 5000;
console.log(port);
app.listen(port);
var remoteUrl = 'http://consoletweet.herokuapp.com/authtoken';
var localUrl = 'http://justunfollow.net:5000/authtoken'
var oauth =
{ callback: remoteUrl
, consumer_key: '#######'
, consumer_secret: '######'
}
, url = 'https://api.twitter.com/oauth/request_token'
;
app.get('/',function(req,res) {
request.post({url:url, oauth:oauth}, function (e, r, body) {
var access_token = qs.parse(body)
appAccessToken = access_token.oauth_token;
console.log(access_token.oauth_token);
res.redirect("https://api.twitter.com/oauth/authenticate?oauth_token="+access_token.oauth_token);
})
});
app.get('/authtoken',function(req,response){
var oauth1 =
{ consumer_key: '########'
, consumer_secret: '#######'
, token: req.query.oauth_token
, verifier: req.query.oauth_verifier
}
, url = 'https://api.twitter.com/oauth/access_token'
;
request.post({url:url,oauth:oauth1},function(e,r,body){
var access_token = qs.parse(body);
array1[access_token.oauth_token] = access_token.oauth_token_secret;
console.log(access_token.oauth_token)
response.send("logged in!! run following commond : tweet -a "+access_token.oauth_token);
});
});
app.get('/sendtweet',function(req,res){
var oauthtoken = req.query.oauth;
var tweet = req.query.tweet;
console.log(tweet)
var oauth2 = {
consumer_key: '######'
, consumer_secret: '######'
, token: oauthtoken
, token_secret: array1[oauthtoken]
}
, url = 'https://api.twitter.com/1.1/statuses/update.json'
;
request.post({url:url,oauth:oauth2,body:"status="+tweet},function(e,r,body){
if(e) {
res.send(e);
}
body = JSON.parse(body);
console.log(body.errors);
if(body["errors"]) {
res.send(body.errors[0].message);
} else {
res.send("tweet sent ..");
}
})
})
process.on('uncaughtException',function(err){
console.log(err);
console.log("Closing");
app.close();
});
process.on('SIGTERM', function(err){
console.log("Closing");
app.close();
});