Find score inside json result of PageSpeed Insight api v5

久未见 提交于 2019-12-04 11:26:27

问题


I'm trying the Google v5 API page speed insight but i don't find the SCORE inside the json result.

This is the api https://www.googleapis.com/pagespeedonline/v5/runPagespeed

In the v4 there is a ruleGroups.SPEED.score that contains an integer with the score.

Where i can find the score inside the v5?

Thanks


回答1:


I think it is the following: json.lighthouseResult.categories.performance.score

Returns a decimal with 1 as maximum. So you have to multiply with 100 to get the percentage. Works for me.. However I don't seem to get the same value every time. It fluctuates...




回答2:


It is json.lighthouseResult.categories.performance.score as described by Jeroen.

You can return all possible audit categories using the following example:

  • URL: https://www.google.com/
  • Return-Fields: lighthouseResult/categories/*/score
    • * is a wildcard
  • Indentations (PrettyPrint): no
  • Strategy: Desktop
  • Categories:
    • Performance
    • Progressive Web App (PWA)
    • Best practices
    • Accessibility
    • SEO
  • Api-Key: {YOUR_API_KEY}
    With these parameters, the API URL is:

    https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https%3A%2F%2Fstackoverflow.com%2F&fields=lighthouseResult%2Fcategories%2F*%2Fscore&prettyPrint=false&strategy=desktop&category=performance&category=pwa&category=best-practices&category=accessibility&category=seo&key={YOUR_API_KEY}


And the JSON-Response looks like this:
{
    "lighthouseResult": {
        "categories": {
            "performance": {
                "score":0.99
            },
            "accessibility": {
                "score":0.7
            },
            "best-practices": {
                "score":0.77
            },
            "seo": {
                "score":0.9
            },
            "pwa": {
                "score":0.56
            }
        }
    }
}


来源:https://stackoverflow.com/questions/53290705/find-score-inside-json-result-of-pagespeed-insight-api-v5

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