-
Notifications
You must be signed in to change notification settings - Fork 0
/
old.js
104 lines (84 loc) · 3.53 KB
/
old.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
96
97
98
99
100
101
102
103
104
const express = require('express');
const bodyParser = require('body-parser');
const request = require('request');
const app = express();
const Twit = require('twit');
// New Twit with Heroku Variables
var T = new Twit({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
// timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
// strictSSL: false, // optional - requires SSL certificates to be valid.
});
app.use(bodyParser.urlencoded({limit: '50mb', extended: false}));
app.use(bodyParser.json({limit: '50mb'}));
var port = process.env.PORT || 4000;
app.use(function(req, res, next) {
// Important
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.get('/', (req, res, next) => {
res.send('Waiting for tweets');
});
app.post('/', (req, res) => {
if(
req.body.name === undefined ||
req.body.name === '' ||
req.body.name === null
){
return res.json({"success": false, "msg": "name not submitted" });
}
var b64content = req.body.media_id;
return res.json({"success": true});
// first we must post the media to Twitter
// uncomment to Work
// T.post('media/upload', { media_data: b64content }, function (err, data, response) {
// // now we can assign alt text to the media, for use by screen readers and
// // other text-based presentations and interpreters
// var mediaIdStr = data.media_id_string
// var altText = "Small flowers in a planter on a sunny balcony, blossoming."
// var meta_params = { media_id: mediaIdStr, alt_text: { text: altText } }
//
// T.post('media/metadata/create', meta_params, function (err, data, response) {
// if (!err) {
// // now we can reference the media and post a tweet (media will attach to the tweet)
// var params = { status: 'loving life #nofilter', media_ids: [mediaIdStr] }
//
// T.post('statuses/update', params, function (err, data, response) {
// console.log(data);
// return res.json({"success": data});
// })
// }
// })
// })
// var message = "Hello world, my name is" + req.body.name + "!";
// T.post('statuses/update', { status: message }, function(err, data, response) {
// //console.log(data);
// return res.json({"success": data});
// })
// // Secret Key from Heroku Config Variable 'RECAPTCHA_SECRET'
// const secretKey = process.env.RECAPTCHA_SECRET;
//
// // Google's verification URL: https://developers.google.com/recaptcha/docs/verify
// const verifyUrl = `https://google.com/recaptcha/api/siteverify?secret=${secretKey}&response=${req.body.captcha}&remoteip=${req.connection.remoteAddress}`;
//
// // Make Request To VerifyURL
// request(verifyUrl, (err, response, body) => {
// body = JSON.parse(body);
//
// // If Not Successful
// if(body.success !== undefined && !body.success){
// return res.json({"success": false, "msg":"Failed captcha verification from live server"});
// }
//
// //If Successful
// return res.json({"success": true, "msg":"Captcha passed from live server"});
// });
});
app.listen(port, function () {
console.log('App listening on port ' + port);
});