从 instagram 主题标签中获取数据属性

Fetching data attributes from instagram hashtag

我想获取存储在 https://www.instagram.com/explore/tags/selfie/?__a=1 中的数据(每个 post 中的图像),但是当我解码时我得到的只是 var_dump 这是 NULL。

$obj = json_decode("https://www.instagram.com/explore/tags/selfie/?__a=1", true);
var_dump($obj);

在解码 json 之前,您必须先获取 api 响应。

$obj = json_decode(file_get_contents("https://www.instagram.com/explore/tags/selfie/?__a=1"), true);

您正在尝试 json_decode STRING

https://www.instagram.com/explore/tags/selfie/?__a=1

您需要做的是先获取 URL。我建议使用 file_get_contents,它采用 URL 和 returns URL 末尾的内容。

试试这个:

$json = file_get_contents("https://www.instagram.com/explore/tags/selfie/?__a=1");
$obj = json_decode($json, true);
var_dump($obj);

函数 json_decode() 的参数 $html 必须是 plaintext/string。 这应该工作。

$url = "https://www.instagram.com/explore/tags/selfie/?__a=1";
$html = file_get_contents($url); 
$obj = json_decode($html,true);
var_dump($obj);

查看实际效果 here