Instagram API返回HTML而不是JSON

时间:2017-03-30 04:22:01

标签: javascript html json node.js instagram-api

当我运行server.js应用程序时,我收到此错误:

{ SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
at IncomingMessage. (/Users/test/Desktop/simple_node_app/node_modules/instagram-node/lib/instagram.js:192:27)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
retry: [Function: retry],
status_code: 404,
etc, etc...

我使用来自浏览器的API调用来测试令牌,它在独立时工作,但server.js文件不断抛出此错误。 这是我的版本:

"dependencies": {
"ejs": "^2.5.6",
"express": "^4.15.2",
"instagram-node": "^0.5.8"
}

服务器文件:

var express = require('express');
var app     = express();
var ig      = require('instagram-node').instagram();

app.use(express.static(__dirname + '/public'));

app.set('view engine', 'ejs');

ig.use({
  access_token: "MY_ACCESS_TOKEN"
});

app.get('/', function(req, res) {
  // console.log(req);
    // use the instagram package to get popular media
        ig.user_self_feed(function(err, medias, pagination, remaining, limit) {
        // render the home page and pass in the popular images
        console.log(err);
        res.render('pages/index', { grams: medias });
    });
});

app.listen(8080);
console.log('App started! Look at http://localhost:8080');

访问令牌有效,当我使用此API时,我得到JSON:

https://api.instagram.com/v1/users/self/media/recent/?access_token=12345(当然不是真的......)

0 个答案:

没有答案