自从
body
是一根绳子,你必须
JSON.parse
获取实际对象:
function getRecent(user_id, access_token, count) {
request
.get(`https://api.instagram.com/v1/users/${user_id}/media/recent/?access_token=${access_token}&count=${count}`, function(err, response, body) {
if (err) {
console.log('subscriptions.js 47 error: ' + err)
}
console.log('subscriptions.js 49 response.statusCode = ' + response.statusCode)
console.log('subscriptions.js 50 body = ' + body)
const json = JSON.parse(body)
console.log('Yay! An actual object:', json)
console.log('And its .data:', json.data)
})
}
if you call it with
json: true
:
function getRecent(user_id, access_token, count) {
request
.get({
url: `https://api.instagram.com/v1/users/${user_id}/media/recent/?access_token=${access_token}&count=${count}`,
json: true
}, function(err, response, body) {
// here body should be an object already
})
}