【问题标题】:get instagram public media using new api使用新的 api 获取 instagram 公共媒体
【发布时间】:2017-11-23 22:27:16
【问题描述】:

我正在尝试在我的 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 个媒体?

【问题讨论】:

    标签: javascript node.js get instagram instagram-api


    【解决方案1】:

    查看此链接返回的 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
    

    ..等等。

    您需要在此处更改我提供给您所需用户名的网址中的aa

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

    【讨论】:

      【解决方案2】:

      你有两个问题:

      首先端点接收用户 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)

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

      【讨论】:

      • 我正在尝试获取此公开个人资料的最后 10 张照片。我应该在哪里查找这些照片的 URL?
      • 我的访问令牌有效,我将用户 ID 更新为公共配置文件的实际用户 ID。现在,我得到:{ meta: { code: 400, error_type: 'APINotFoundError', error_message: 'this user does not exist' } } ...你能帮忙吗?
      • 您的问题可能是您的应用尚未经过 Instagram 审核。查看此链接:instagram.com/developer/review
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-14
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多