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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。