2017-03-09 80 views
0

我可以通過公共API獲取Instagram的照片與下面的代碼(如How to get all images of hashtag in Instagram without API?看到)獲取所有用戶的媒體 - Instagram的

<?php 

$baseUrl = 'https://www.instagram.com/explore/tags/girls/?__a=1'; 
$url = $baseUrl; 

while(1) { 
    $json = json_decode(file_get_contents($url)); 
    print_r($json->tag->media->nodes); 
    if(!$json->tag->media->page_info->has_next_page) break; 
    $url = $baseUrl.'&max_id='.$json->tag->media->page_info->end_cursor; 
} 

然而,這個代碼返回給我的只有95媒體,即使用戶有1000+媒體(任何用戶)

有什麼問題嗎?

感謝

+0

將字面上的所有媒體發送給你的開銷成本對於instagram來說是不值得的。我認爲95應該足夠多,但是應該有一種通過它分頁的方式。你知道他是如何獲得這種聯繫的,我從來沒有見過它。 – Neil

+0

不要重新發明輪子:https://github.com/postaddictme/instagram-php-scraper –

+0

嗯...我會看看。謝謝:) –

回答

1

你爲什麼不使用instagram-php-scraper

通過作曲家安裝它,您的服務器上創建一個新的目錄,然後輸入您的控制檯上執行以下操作:

composer require raiym/instagram-php-scraper 

然後只需使用:

<?php 
require 'vendor/autoload.php'; 
use InstagramScraper\Instagram; 
$medias = Instagram::getMediasByTag('pedro', 200); 
header('Content-Type: application/json'); 
echo json_encode($medias); 

檢查所有可用的方法:

https://github.com/postaddictme/instagram-php-scraper/blob/master/README.md

+0

我來看看。謝謝 :) –

相關問題