google-api-php-client: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential

Hello all I’m trying to reach google analytics scope in order to get the total visitors to my sit but i get this error when I use the json file of Outh 2.0 in the setConfig method

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

Why this happened i need to know

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I’ll reply with an example tomorrow. If I don’t send me a dm

On Mon, 18 Sep 2023 at 17:22, oolul @.***> wrote:

Sorry @benrcole https://github.com/benrcole I’m not sure to understand what you’re suggesting.

I’ve tried to do it with the library (v2.14.0 and v2.15.1) and it failed. After that I tried to do manual requests myself and still having the same error at the same step of the process and I can tell you that I’m sure that the Authorization header is present on my request.

What I’ve tried to make sure my access_token was valid is to put a fake one when I try to fetch an asset or update the match policy and it failed so that confirms that my access_token is valid or at least for those endpoints…

Could you be more explicit of what works for you ? And are you doing a reference file upload too ?

Thanks

— Reply to this email directly, view it on GitHub https://github.com/googleapis/google-api-php-client/issues/2479#issuecomment-1723696165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWOZT6FY4QTYLDFKTZXBY3X3BRKDANCNFSM6AAAAAA2YBCBQQ . You are receiving this because you were mentioned.Message ID: @.***>

I also had the same issue.

Sending the request through the library rather than getting the client and sending yourself is a workaround you could try, this works for me

On Mon, 18 Sep 2023 at 16:52, oolul @.***> wrote:

Hey guys,

Still having the same error (even with the v.2.15.1) but I think is neither the PHP Client library or my code the issue. Below you can see that I’m not the only one having the same issue and people are saying that they didn’t change anything in their code too

https://issuetracker.google.com/issues/300280233 https://issuetracker.google.com/issues/300236995

I’ll keep an eye of those issues and will let you know if Google answer

— Reply to this email directly, view it on GitHub https://github.com/googleapis/google-api-php-client/issues/2479#issuecomment-1723608661, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWOZT2VVLQ7Y4ZLZACFOE3X3BN35ANCNFSM6AAAAAA2YBCBQQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>