I'm trying to access Google Analytics in order to get the page views of my site, but due to the update in GA4 I'm unable to access it through the client_secrets.json file. I'm getting this error:

"
"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"
            }
        }
    ]
}
}"

What do I have to do and how can I use the property id instead of the view id? I only need to get the page views of all my site pages.


my php-v 7.3

laravel platform 7

1

There are 1 best solutions below

0
vdhoangson On
  1. Create google service account https://cloud.google.com/iam/docs/service-accounts-create
  2. Download file auth json
  3. Config laravel env GOOGLE_APPLICATION_CREDENTIALS=/path-to-file-auth

I hope I can help you