如何在 PHP 的本地主机中使用 Page Speed Insight API?

How to use Page Speed Insight API in localhost with PHP?

您好,我正在尝试使用 google 速度见解 API 在 PHP

中获取页面速度见解
$api = 'API KEY';
$url = 'https://www.whosebug.com/';
$url_sh = "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=".$url."&key=".$api;

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url_sh);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));

但结果得到 NULL 值

我也试过 json_decode 但得到相同的输出

版本 1 api 很久以前就被弃用了,最新版本是版本 5,所以您只需要将 url 更改为

https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=".$url."&key=".$api;

你可以read the getting started documents here