我正在尝试设置一个应用程序,用一个标签实时显示Instagram帖子。
这是我到目前为止所拥有的。
var io = require('socket.io').listen(app)
, fs = require('fs')
, connect = require('connect')
, $ = require('jquery')
// , ngrok = require('ngrok')
, express = require('express')
, app = express()
, port = process.env.PORT || 5000;
//ngrok.connect(5000, function (err, url) {
//})
app.listen(port);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.emit('stuff', function() {
console.log("http server listening on %d", port);
});
socket.on('my other event', function (data) {
console.log(data);
});
});
// Defining Routes
app.use(express.static(process.cwd() + '/public'));
app.get('/', function (req, res) {
res.send('Testing');
});
app.get('/endpoint', function (req, res) {
// For convention's sake, we only respond to this if it's a properly formatted request from Instagram
if (req.query['hub.challenge']) {
// First we check if hub.challenge exists in the query, then we do something
res.send(req.query['hub.challenge']);
}
});
这是我错了/丢失的地方
app.use(express.bodyParser());
app.post('/endpoint', function (req, res) {
console.log(req.body);
});
我相信我已经按照Instagram API中的订阅教程(设置hub.challenge并设置了订阅)但是如何查看它应该发送的传入JSON数据?最重要的是,我如何操纵JSON以在前端显示图片?
感谢任何帮助!