douxing5598 2016-01-30 12:12
浏览 250
已采纳

如何使用Instagram的API获取媒体ID

I've been trying to retrieve the users who have commented on a picture at Instagram. The issue I'm facing is that you require the media ID of the image to use in the api endpoint. I'm using this code to get the media ID of the image:

$api = file_get_contents("http://api.instagram.com/oembed?url=https://www.instagram.com/p/BBHOUQyuS3T/?taken-by=kimkardashian");
$apiObj = json_decode($api,true);
$media_id = $apiObj['media_id'];
print_r($media_id);

which gives me a media ID of 1172969193024859603_18428658.

When I input this into my api request like this:

$api = file_get_contents("http://api.instagram.com/v1/media/".$media_id."/comments?access_token=".$access_token);

with my particular access_token, I get a 400 error code. When I go direct to the page url, it says:

Invalid media id.

Has anyone else had this problem before? If so how did you solve it?

Another puzzling part of this is that, after looking around the Stackoverflow for a while, I found a couple ways of translating the shortcode for the picture into the media ID.

One of them is nodejs module here which gives me a media ID for the image of 1172969193024859603, so like the original but without the bit after the underscore. Both ID's give me the same error.

I've been at this for hours and it's driving me mad! Please help.

  • 写回答

1条回答 默认 最新

  • dqrnsg6439 2016-01-31 15:59
    关注

    Thats the expected response in sandbox mode if you are trying to access a user's media that is not in your sandbox authorized user list.

    https://www.instagram.com/developer/sandbox/

    Data is restricted to sandbox users and the 20 most recent media from each sandbox user

    Add the user who's photo u want to access to your sandbox users, then you will get a valid API response for media

    The media_id 1172969193024859603_18428658 and 1172969193024859603 are the same the part after underscore is the media owner's user_id, both are valid for media_id

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B