使用新 api 获取 instagram public 媒体

get instagram public media using new api

我正在尝试在我的 nodejs 应用程序中获取 public 个人资料的 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."}}

为什么会这样?我只是想获取一些 public 个人资料供稿。

更新 3:

是否有任何其他方法可以绕过这些访问令牌权限并仅获取 public 用户的第 10 个媒体?

你有两个问题:

首先端点接收用户 ID 作为参数(不是用户名):

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).

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

看看这个 link 返回的 json: 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