OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Instagram API returning HTML instead of JSON

  • Thread starter Thread starter Captain Chaos
  • Start date Start date
C

Captain Chaos

Guest
When I run the server.js app I get this error:

Code:
{ 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...

I tested the token with an API call from the browser, it works when it is standalone, but the server.js file keeps throwing this error. Here are my versions:

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

server file:

Code:
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) {
        // 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');

The access token works, when I use this API, I get JSON:

https://api.instagram.com/v1/users/self/media/recent/?access_token=12345 (not real, of course...)

<p>When I run the server.js app I get this error:</p>
<pre><code>{ 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...
</code></pre>
<p>I tested the token with an API call from the browser, it works when it is standalone, but the server.js file keeps throwing this error.
Here are my versions:</p>
<pre><code>"dependencies": {
"ejs": "^2.5.6",
"express": "^4.15.2",
"instagram-node": "^0.5.8"
}
</code></pre>
<p>server file:</p>
<pre><code>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) {
// 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');
</code></pre>
<p>The access token works, when I use this API, I get JSON:</p>
<p><a href="https://api.instagram.com/v1/users/self/media/recent/?access_token=12345" rel="nofollow noreferrer">https://api.instagram.com/v1/users/self/media/recent/?access_token=12345</a> (not real, of course...)</p>
 
Top