使用新的API获取Instagram公共媒体

我试图在我的nodejs应用程序中获得公共个人资料的10张最新Instagram照片:

const request = require('request'); const accessToken = '1234567890123456789012345678901234567890'; const url = `https://api.instagram.com/v1/users/1470414259/media/recent/?access_token=${accessToken}&count=10`; request.get(url, { json: true }, (err, res, body) => { console.log('print the body: ', body); }); 

我的尝试不成功,我没有结果。 有人可以帮我做这个吗?

我试图按照这里的例子: https : //www.instagram.com/developer/endpoints/users/#get_users_media_recent

更新:

我更新了用户名到用户ID,但我仍然没有得到任何回应:

 { meta: { code: 400, error_type: 'APINotFoundError', error_message: 'this user does not exist' } } 

更新2:

其实我意识到我的访问令牌有一些限制:

 {"meta": {"code": 400, "error_type": "OAuthPermissionsException", "error_message": "This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions."}} 

为什么会这样呢? 我只是想获得一些公开的个人资料提要。

更新3:

有没有其他的方式来绕过这些访问令牌的权限,只获得一个公共用户的10媒体?

看看这个链接返回的JSON: https://www.instagram.com/aa/?__a=1 : https://www.instagram.com/aa/?__a=1

  body.user.media[0] will give you the last photo object body.user.media[1] will give you the photo before the last one object 

.. 等等。

你必须做的是在我提供给你想要的用户名的url中更改aa

PS。 如果浏览器不支持,可以使用一些json查看器工具来组织json

你有两个问题:

首先,端点将用户标识作为参数(不是用户名)接收:

 const url = `https://api.instagram.com/v1/users/${userId}/media/recent/?access_token=${accessToken}&count=10`; 

除此之外,端点只响应一个只有一个元素的对象: data ,即数组。 所以我不知道你想获得什么样的数据,但是你不会在body.user得到它,你应该通过数组并询问相应位置的用户,例如试试这个: console.log(body.data[0].user)

而你当然必须定义一个有效的访问令牌!