Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed instagram api call paths

  • Loading branch information...
commit 14c5efa5a85a0213115ee9af6b1e2e3ad1da7604 1 parent 2184590
@JustinBeckwith authored
View
52 backend/routes/home.js
@@ -4,9 +4,6 @@ module.exports = function (app, nconf, serviceBusService) {
// home page
app.get('/', function (req, res) {
-
-
-
res.render('index', { title: 'Home Page. ' })
});
@@ -22,28 +19,47 @@ module.exports = function (app, nconf, serviceBusService) {
res.send(req.query['hub.challenge']);
});
+ var minIds = new Object();
app.post('/newimage/:city', function (req, res) {
var data = req.body;
+ console.log(data);
data.forEach(function (img) {
- var url = "https://api.instagram.com/v1/media/" + img.object_id + "?client_id=" + nconf.get('instagramClientId');
+
+ var lastId = minIds[req.params.city];
+
+ var url = "https://api.instagram.com/v1/geographies/" + img.object_id + "/media/recent?client_id=" + nconf.get('instagramClientId');
+ if (lastId) {
+ url += "&MIN_ID=" + lastId;
+ }
+
console.log(url);
request(url, function (e, r, b) {
- var pic = {
- city: req.params.city,
- pic: b
- }
- console.log(pic);
- var message = {
- body: JSON.stringify(pic)
- };
- serviceBusService.sendTopicMessage('wazages', message, function (error) {
- if (error) {
- console.log('error sending message to topic - ' + error);
- } else {
- console.log('message sent!');
+ var data = JSON.parse(b);
+ if (data.meta.code == 200) {
+
+ //var lastRecord = data.data[data.data.length - 1];
+ var lastId = data.pagination.next_min_id;//lastRecord.id;
+ console.log('lastId for ' + req.params.city + ' is ' + lastId);
+ minIds[req.params.city] = lastId;
+
+ var pic = {
+ city: req.params.city,
+ pic: b
}
- })
+ var message = {
+ body: JSON.stringify(pic)
+ };
+ serviceBusService.sendTopicMessage('wazages', message, function (error) {
+ if (error) {
+ console.log('error sending message to topic - ' + error);
+ } else {
+ console.log('message sent!');
+ }
+ })
+ } else {
+ console.log("ERROR::getMedia:: " + data.meta.error_message);
+ }
});
})
res.end();
View
3  frontend/server.js
@@ -87,8 +87,7 @@ function getFromTheBus() {
}
} else {
var body = JSON.parse(message.body);
- console.log('new pic published from: ' + body.city);
- console.log(io.sockets.in(body.city));
+ console.log('new pic published from: ' + body.city);
io.sockets.in(body.city).emit('newPic', body.pic);
}
getFromTheBus();
View
4 frontend/views/images.html
@@ -28,7 +28,9 @@
console.log('got a new pic!!!')
var p = JSON.parse(pic);
console.log(p);
- $("#pics").append($("<img src=\"" + p.data.images.low_resolution.url + "\">"));
+ for (var i = 0; i< p.data.length; i++ ) {
+ $("#pics").append($("<img src=\"" + p.data[i].images.low_resolution.url + "\">"));
+ }
});
})
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.