【问题标题】:Fetching data attributes from instagram hashtag从 instagram hashtag 中获取数据属性
【发布时间】:2018-06-01 06:52:20
【问题描述】:

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

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

【问题讨论】:

  • 如何获取“profile_pic_url”?

标签: php json instagram


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您正在尝试json_decode STRING

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

    您需要做的是首先获取 URL。我建议使用file_get_contents,它接受一个 URL 并返回该 URL 末尾的内容。

    试试这个:

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

    【讨论】:

    • 这是一个关于遍历 JSON 结构的不同问题。我会在这里接受最佳答案,然后再问一个问题。
    【解决方案3】:

    函数json_decode()的参数,$html必须是明文/字符串。 这应该有效。

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

    看看这个here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多