-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
75 lines (63 loc) · 2.37 KB
/
server.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
var express = require("express");
var app = express();
var port = process.env.PORT || 80;
var io = require('socket.io').listen(app.listen(port));
var Instagram = require('instagram-node-lib');
var http = require('http');
var request = ('request');
var intervalID;
var pub = __dirname + '/public',
view = __dirname + '/views';
var clientID = 'df8f2e7775d641ea85f6978c799c411b',
clientSecret = 'dc9a9281ea8c49bf973f2a98576d7934';
io.configure(function () {
io.set("transports", [
'websocket'
, 'xhr-polling'
, 'flashsocket'
, 'htmlfile'
, 'jsonp-polling'
]);
io.set("polling duration", 10);
});
Instagram.set('client_id', clientID);
Instagram.set('client_secret', clientSecret);
Instagram.set('callback_url', 'http://festpizza.herokuapp.com/callback');
Instagram.set('redirect_uri', 'http://festpizza.herokuapp.com');
Instagram.set('maxSockets', 10);
Instagram.subscriptions.subscribe({ object: 'tag', object_id: 'festpizza' });
Instagram.subscriptions.subscribe({ object: 'tag', object_id: 'festpizza2014' });
// Instagram.subscriptions.subscribe({ object: 'tag', object_id: 'gopro' });
io.sockets.on('connection', function (socket) {
Instagram.tags.recent({
name: 'festpizza',
complete: function(data) {
socket.emit('firstShow', { firstShow: data });
}
});
});
//https://api.instagram.com/v1/subscriptions?client_secret=dc9a9281ea8c49bf973f2a98576d7934&client_id=df8f2e7775d641ea85f6978c799c411b
//curl -X DELETE 'https://api.instagram.com/v1/subscriptions?client_secret=dc9a9281ea8c49bf973f2a98576d7934&object=all&client_id=df8f2e7775d641ea85f6978c799c411b'
// Instagram.subscriptions.unsubscribe({ id: '3668016' });
// Instagram.subscriptions.unsubscribe({ id: '8746292' });
app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(pub));
app.use(express.static(view));
app.use(express.errorHandler());
});
app.get('/callback', function(req, res){
var handshake = Instagram.subscriptions.handshake(req, res);
});
app.post('/callback', function(req, res) {
console.log(req);
var data = req.body;
data.forEach(function(tag) {
var url = 'https://api.instagram.com/v1/tags/' + tag.object_id + '/media/recent?client_id=' + clientID;
io.sockets.emit('show', { show: url });
});
res.end();
});
console.log("Listening on port " + port);