2016-04-10 57 views
0

我想从JSON网址中提取任何instagram用户的profile_picture:https://www.instagram.com/just/media/用PHP打印出来。我已经试过:Instagram JSON头像提取PHP

$instaJSONUrl = 'https://www.instagram.com/just/media/'; 
$json = file_get_contents($instaJSONUrl); 
$json_data = json_decode($json, true); 
echo $json_data["profile_picture"]; 

不工作。如果我打印出$ JSON而已,我得到:

{status":"ok","items":[],"more_available":false} 

也就意味着问题是读取URL。这是否意味着我需要访问令牌,因为我不想使用它,因为当我从浏览器打开https://www.instagram.com/just/media/时,我已经可以获取配置文件图像URL。

回答

1

这将产生一组用户及其图片配置文件链接。

<?php 

$instaJSONUrl = 'https://www.instagram.com/just/media/'; 
$json = file_get_contents($instaJSONUrl); 
$json_data = json_decode($json, true); 

$users = array(); 

foreach($json_data['items'] as $item) 
    foreach($item['comments'] as $comment) 
      foreach($comment as $profile) 
        $users[$profile['from']['username']] = $profile['from']['profile_picture']; 


print_r($users); 
+0

问题是,它无法访问整个JSON,就像它通过浏览器打开时一样。基本上它读为:{状态“:”确定“,”项目“:[],”more_available“:false},所以它没有任何项目。检查出我得到的解决方案:-) –

+0

啊,很高兴你有它的工作 –

0

成功地通过直接访问meta标签做到这一点,并专门<meta property="og:image"标签,有如下:

libxml_use_internal_errors(true); 
$c = file_get_contents($instaURL); 
$d = new DomDocument(); 
$d->loadHTML($c); 
$xp = new domxpath($d); 

,然后我可以打印出与图像网址:

foreach ($xp->query("//meta[@property='og:image']") as $el) { 
    echo $el->getAttribute("content"); 
} 


您甚至可以使用它来访问其他属性,如og:urlog:description为特定的Instagram用户。

这是所有那些需要访问的人&获取Instagram用户数据(基本:profile_image,profile_url,profile_description等),而不涉及Instagram的API。