我希望在某个标签上进行实时更新,并在屏幕上打印图片。我在使用instagram-node-lib模块设置node.js服务器时遇到问题。但是我在运行文件时仍然收到错误(node server.js);
https://github.com/mckelvey/instagram-node-lib
这是我的实现(server.js使用express 3.5.1):
var express = require("express");
var app = express();
var port = process.env.PORT || 3000;
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 = '*****',
clientSecret = '*****';
Instagram.set('client_id', clientID);
Instagram.set('client_secret', clientSecret);
Instagram.set('callback_url', 'http://my_url.com/callback');
Instagram.set('redirect_uri', 'http://my_url.com');
Instagram.set('maxSockets', 10);
Instagram.subscriptions.subscribe({
object: 'tag',
object_id: 'lol',
aspect: 'media',
callback_url: 'http://my_url.com/callback',
type: 'subscription',
id: '3'
});
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){
Instagram.subscriptions.handshake(req, res);
});
app.post('/callback', function(req, res) {
var data = req.body;
// Grab the hashtag "tag.object_id"
// concatenate to the url and send as a argument to the client side
data.forEach(function(tag) {
var url = 'https://api.instagram.com/v1/tags/' + tag.object_id + '/media/recent?client_id=******';
sendMessage(url);
});
res.end();
});
console.log("Listening on port " + port);
一切似乎都很好,但在运行命令(node server.js)时,我得到:
info - socket.io started
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Listening on port 3000
APISubscriptionError occurred: Invalid response in _request
(我也有socket.io的东西,但是我把它留在那里专注于这个问题。)
APISubscriptionError与我尝试和执行的订阅量直接相关。在这种情况下,只考虑标签“lol”的一个。我只想顺利运行,没有这个错误。
答案 0 :(得分:0)
我能够找到我的问题,它与Instagram-node-lib(这是一个病态的btw)无关。我需要将我的所有网址定义为http://MY_URL.com:3000,因为我在端口3000上运行。这在尝试订阅我的回调网址时会产生冲突。为了使它不需要使用:3000后缀,似乎我需要通过nginx为端口80创建代理来运行节点。