Get overall score in google pagespeed curl request-PHP

筅森魡賤 提交于 2020-01-11 14:13:28

问题


I am using v4 google pagespeed API which is till now working fine but suddenlt I get {{BEGIN_LINK}}, {{END_LINK}} in response, I think that should be removed before we get curl response. To overcome this issue I thought to try v5, but it seems v5 response is complex to understand as compared to v4. And my question is how can I get Page Score(0-100) in v5? My code is :

$curl_data = curl_request("https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.ex.com&strategy=desktop", '', 'GET');
$json_data = json_decode($curl_data);

In v4, I am using $data = $json_data->formattedResults->ruleResults; $pageScore = $json_data->ruleGroups->SPEED->score; to get required details. But in V5 I did not found formattedResults or ruleGroups.


回答1:


The returned JSON has a section under lighthouseResult called categories.

Within categories you will see performance and then score is a child there with the score out of 1 (so a score of 89 would be 0.89).

"lighthouseResult": {
......
    "categories": {
        "performance": {
            "id": "performance",
            "title": "Performance",
            "score": 1.00, <- here is the score.
            "auditRefs":
......


来源:https://stackoverflow.com/questions/58801771/get-overall-score-in-google-pagespeed-curl-request-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!