【问题标题】:json_decode url instagram return Null with PHP codejson_decode url instagram 使用 PHP 代码返回 Null
【发布时间】:2023-03-23 03:30:01
【问题描述】:

我有一个来自 json_decode url instagram https://www.instagram.com/username/?__a=1 使用 php 返回 Null 的问题

        $newwul = "http://www.instagram.com/username/?__a=1";
        $xo =  connect($newwul);
        $xx = json_decode($xo,true);
        $endcount = $xx['logging_page_id'];
        $userid = $xx['graphql']['user']['id'];
        var_dump($xo);//return NULL
        var_dump($xx);//return NULL

它们是我的函数连接

function connect($urlx){
    $cookie_file_path = "cookies/c.txt";
    $agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36";

    $urlex = ($urlx);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $urlex);

    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'cookie:ig_cb=1; rur=PRN; mid=XV_v7gAEAAFbvgXMUd0PClkTvnla; csrftoken=fs1r3L5SxkJvrN6g2w239nhMgppQGVLc; urlgen="{\"185.56.80.156\": 43350}:1i2zL0:8TaH7yECjymjQH80LduQiFUJZE0"',
   ));
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);

    curl_setopt($ch, CURLOPT_REFERER, $urlex);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,100);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    return $req = curl_exec($ch);
    curl_close($ch);
}

请问有什么解决办法吗?

【问题讨论】:

  • 因为您的连接函数返回空值。您可能无法使用 curl 连接到 Instagram。请重新检查 curl 的错误:php.net/manual/en/function.curl-error.php
  • Au Nguyen 谢谢你的回答 没有函数 connect() 我仍然有同样的问题 我认为链接中存在问题 例如 这个 url 没问题 ``` $newwul = "@ 987654323@"; $xo = 连接($newwul); $xx = json_decode($xo,true); $endcount = $xx['状态'];回声 $endcount; //REQUEST_DENIED ```
  • Au Nguyen 谢谢你的回答 没有函数 connect() 我仍然有同样的问题 我认为链接中有问题 例如 这个网址没问题link
  • 我猜你已经达到了 Instagram 的请求速率限制,回复是null

标签: php json url instagram


【解决方案1】:

请查看 curl instagram 的示例:

<?php
$newwul = "http://www.instagram.com/username/?__a=1";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $newwul);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERAGENT, " Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$data_curl = curl_exec($curl);
curl_close($curl);

var_dump($data_curl);
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 2018-05-27
    • 1970-01-01
    相关资源
    最近更新 更多