forked from ak2consulting/singly-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
54 lines (43 loc) · 1.44 KB
/
test.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
var Singly = require('./lib');
var express = require('express');
var clientID = process.argv[2];
var clientSecret = process.argv[3];
var singly = new Singly(clientID, clientSecret, 'http://localhost:8044/callback');
var app = express.createServer();
var accessToken;
app.get('/', function(req, res) {
res.redirect(singly.getAuthorizeURL('facebook'));
});
app.get('/callback', function(req, res) {
singly.getAccessToken(req.param('code'), function(err, access_token) {
accessToken = access_token;
res.redirect('/all');
});
});
app.get('/all', function(req, res) {
if (!accessToken) return res.redirect('/');
singly.get('/types/all', {access_token:accessToken}, function(err, resp, body) {
if(err) return res.send(err, 500);
res.send(body);
});
});
app.post('/status', function(req, res) {
if (!accessToken) return res.send('must auth at http://localhost:8044/', 401);
var qs = req.query;
qs.access_token = accessToken;
singly.post('/types/statuses', {qs:qs}, function(err, resp, body) {
if (err) return res.send(err, 500);
res.send(body);
});
});
app.post('/link', function(req, res) {
if (!accessToken) return res.send('must auth at http://localhost:8044/', 401);
var qs = req.query;
qs.access_token = accessToken;
singly.post('/types/links', {qs:qs}, function(err, resp, body) {
if (err) return res.send(err, 500);
res.send(body);
});
});
app.listen(8044);
console.log('open http://localhost:8044');