请求缺少所需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他 laravel google/apiclient

问题描述 投票:0回答:1

我正在尝试访问 Google Analytics 以获取我网站的页面浏览量,但由于 GA4 中的更新,我无法通过 client_secrets.json 文件访问它。我收到此错误:

"
"error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
        { "message": "Login Required.",
          "domain": "global",
          "reason": "required",
          "location": "Authorization",
          "locationType": "header"
        }
    ],
    "status": "UNAUTHENTICATED",
    "details": [
        { 
          "@type": "type.googleapis.com/google.rpc.ErrorInfo",
          "reason": "CREDENTIALS_MISSING",
          "domain": "googleapis.com",
          "metadata": {
              "service": "analyticsreporting.googleapis.com",
              "method": "google.analytics.reporting.v4.Reporting.GetReports"
            }
        }
    ]
}
}"

我必须做什么以及如何使用属性 id 而不是视图 id?我只需要获取我所有网站页面的页面浏览量。


我的 php-v 7.3

laravel 平台 7

laravel google-api-client pageviews google-analytics-4
1个回答
0
投票
  1. 创建谷歌服务帐户https://cloud.google.com/iam/docs/service-accounts-create
  2. 下载文件auth json
  3. 配置 laravel env GOOGLE_APPLICATION_CREDENTIALS=/path-to-file-auth

希望能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.