在PageSpeed Insight API v5的json结果中查找分数

ber*_*oft 7 api pagespeed google-pagespeed

我正在尝试Google v5 API页面速度分析,但是在json结果中找不到SCORE。

这是api https://www.googleapis.com/pagespeedonline/v5/runPagespeed

在v4中,有一个ruleGroups.SPEED.score,其中包含带有分数的整数。

在哪里可以找到v5内的分数?

谢谢

use*_*808 8

如Jeroen所述,它是json.lighthouseResult.categories.performance.score

您可以使用以下示例返回所有可能的审核类别:

  • 网址: https://www.google.com/
  • 返回字段: lighthouseResult/categories/*/score
    • * 是通配符
  • 缩进(PrettyPrint): no
  • 战略: Desktop
  • 分类:
    • Performance
    • Progressive Web App (PWA)
    • Best practices
    • Accessibility
    • SEO
  • api键: {YOUR_API_KEY}
    使用这些参数,API URL为:

    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- = accessibility&category = seo&key = {YOUR_API_KEY}


JSON-Response看起来像这样:

{
    "lighthouseResult": {
        "categories": {
            "performance": {
                "score":0.99
            },
            "accessibility": {
                "score":0.7
            },
            "best-practices": {
                "score":0.77
            },
            "seo": {
                "score":0.9
            },
            "pwa": {
                "score":0.56
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

我认为它是以下内容:json.lighthouseResult.categories.performance.score

返回最大为1的十进制数。因此,您必须乘以100才能得到百分比。为我工作。。但是我似乎并没有每次都获得相同的价值。波动...