Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Instagram API返回HTML而不是JSON_Javascript_Html_Json_Node.js_Instagram Api - Fatal编程技术网

Javascript Instagram API返回HTML而不是JSON

Javascript Instagram API返回HTML而不是JSON,javascript,html,json,node.js,instagram-api,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)

当我运行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...
服务器文件:

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:


(当然不是真的……

n1t0两年前出版。可能软件包已经过时。我想,您正在尝试使用的api可能返回html格式的错误,这就是为什么您会遇到这个意外的令牌错误。@DavidR我回家后会看一看,我想您是对的,它可能是html格式的404页。我会让你知道的。@hisener什么是n1t0?“我不认识那个名字。”船长说,“包裹的主人。”。(instagram节点)n1t0于2年前发布。可能软件包已经过时。我想,您正在尝试使用的api可能返回html格式的错误,这就是为什么您会遇到这个意外的令牌错误。@DavidR我回家后会看一看,我想您是对的,它可能是html格式的404页。我会让你知道的。@hisener什么是n1t0?“我不认识那个名字。”船长说,“包裹的主人。”。(instagram节点)
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');