问题
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