googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
280 stars 260 forks source link

After upgrading V21.1 getting USER_PERMISSION_DENIED issues. #990

Closed mjainavas closed 6 months ago

mjainavas commented 7 months ago

Which version of the client library are you using? 21.1.0

Which version of PHP are you using? PHP-FPM 8.2

Which operating system (Linux, Windows, ...)? CentOS

Issue is happening with me too, as things are working normal to get spent per account but after upgrading API to V15 via, composer require googleads/google-ads-php:21.1 then I started getting this issue.

get ApiException was thrown with message '{
    "message": "The caller does not have permission",
    "code": 7,
    "status": "PERMISSION_DENIED",
    "details": [
        {
            "@type": "type.googleapis.com\/google.ads.googleads.v15.errors.GoogleAdsFailure",
            "errors": [
                {
                    "errorCode": {
                        "authorizationError": "USER_PERMISSION_DENIED"
                    },
                    "message": "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https:\/\/developers.google.com\/google-ads\/api\/docs\/concepts\/call-structure#cid"
                }
            ],
            "requestId": "UAoxxxxxxxxxxxxxjKdc4rw"
        }
    ]
}'.

Wondering , how it can get fix, or what changes I need to make, I have gone through the documents https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid

any Idea what to do next?

I am using https://github.com/googleads/google-ads-php and upgraded it on 21.1

Thanks

fiboknacky commented 7 months ago

If you've not made any changes to your code, it's likely that it's caused by the recent unintentional breaking change of google/gax. Could you please run composer update to update it to the latest version?

mjainavas commented 7 months ago

Yes, I run the composer require googleads/google-ads-php:21.1 and composer update googleads/google-ads-php

Do you want me to upgrade google/gax version also? If yes then what would be the competible version with 21.1

mjainavas commented 7 months ago

I have tried again by composer require google/gax and composer require googleads/google-ads-php:22.0

but getting same issue: Modules\ADS\Services\Google\Contracts\SpendsPerAccount::get ApiException was thrown with message '{ "message": "The caller does not have permission", "code": 7, "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com\/google.ads.googleads.v15.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "authorizationError": "USER_PERMISSION_DENIED" }, "message": "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https:\/\/developers.google.com\/google-ads\/api\/docs\/concepts\/call-structure#cid" } ], "requestId": "DOLQJqNSm09UQJPhBPp7ow" } ] }'.

fiboknacky commented 7 months ago

Could you share your google/gax version too?

mjainavas commented 7 months ago

Yes, its "google/gax": "^1.26",

fiboknacky commented 7 months ago

Could you tell the exact version that is installed in your project? (You can see that in composer.lock file) I ask because 1.26.2 will have this bug fixed, but 1.26.1 will not.

mjainavas commented 6 months ago

In composer.lockfile It looks like this,

image

But in my project I installed it additionally by composer require google/gax:1.26.3

Also I have updated the composer by composer update

But still getting same error. Any Idea to run with v15 as my existing API code calling v13 which is going to sunset on 30th January. and I wanted to upgrade it to v15

fiboknacky commented 6 months ago

Another way to quickly check this is, in the vendor directory, do you see the change like in this PR?

And I know you haven't changed anything, but just to be sure, what's the customer ID you want to access, and did you try regenerating a refresh token using the Google account that can access that customer?

mjainavas commented 6 months ago

Yes I can see the Code in GAX directory.

         } else {
         // Ads is using this method in their new surface clients, so we need to call it.
        // However, this method is not used anywhere else for the new surface clients
        // @TODO: Remove this in GAX V2
        $this->modifyClientOptions($options);
    }

And customeID and other details I can share with you via email or slack if we can connect over there. It's strange that if all things are perfect then why I am getting same error again and again.

fiboknacky commented 6 months ago

Could you please post on the Google Ads API forum first? There will be a function Reply privately to author where we can exchange files that are more sensitive like credentials. Once you do it, please let me know the link to that forum so I can take over there. Thanks!

And I know you haven't changed anything, but just to be sure, what's the customer ID you want to access, and did you try regenerating a refresh token using the Google account that can access that customer?

BTW, did you try above too?

DorsetDevStudio commented 6 months ago

Wonder if there is a resolution to this as I have exactly the same problem, all worked fine for years until I bumped the ads lib version above "^19.0.0"

Environment: docker image FROM php:8.0-apache

The most recent working combination is composer version "^19.0.0" targeting API Version V14

I've checked all the higher versions of the composer library and they all fail with this error:

"The caller does not have permission"

I'm using a service account, impersonating an email, Implementation below: (as mentioned this all works fine until updating to "googleads/google-ads-php": "^20.0" or above. (I've had to revert to 19 for now).

image

image

image

fiboknacky commented 6 months ago

@DorsetDevStudio There are a couple of factors that can possibly affect this. When you mentioned, your code has worked for years, what client library version and the Google Ads API version you've been using?

DorsetDevStudio commented 6 months ago

@fiboknacky Hi, I have used many versions as you'd expect, given the release schedule.

Library version "^19.0.0" with API Version V14 being the highest version that still works, all older versions work too.

Library version 20 and above do not work.

Thanks. Stuart

fiboknacky commented 6 months ago

So, it sounds like after upgrading to v15, your request starts to fail. The changes that would be related to the permission thing is in the Account Management section. Is there any item that may be applied to your case?

The bug of google/gax is fixed in v1.26.2, but I see you already upgraded to v1.26.3, so that shouldn't be a problem anymore.

Could you please post on the Google Ads API forum first? There will be a function Reply privately to author where you can send me a request and response log. Please include a link to this GitHub issue and mention that the PHP client library owner ask you to send your information. Thanks.

mjainavas commented 6 months ago

Yes, I posted over there already but no solution at all.

fiboknacky commented 6 months ago

@mjainavas Did you mention the link to this GitHub issue? And what's your post? Could you share it here too?

mjainavas commented 6 months ago

@fiboknacky Yes Here it is:

https://groups.google.com/g/adwords-api/c/dQTWw4PDxRk/m/jzc5DrgGBgAJ

https://groups.google.com/g/adwords-api/c/sA2CBGayJdU/m/M04GD1a5AQAJ

https://groups.google.com/g/adwords-api/c/tOjoRIUPWLQ/m/q_rOnVM_AAAJ

But all of the responses I got there is automated, Still not able to figure out why it is not working.

So far I am using 19.2 version as it is supporting v14 API call which is ok till May2024 but For future usecase I wanted to upgrade it till v15.

fiboknacky commented 6 months ago

@mjainavas Thanks for your information. I checked those posts and the log you shared (request id 6BZqXXXXXXXX) and found that you sent a request with login-customer-id to be the same as your customer_id (it's 7108xxxxxx) to GoogleAdsService, correct?

Could you try sending a request to v14 and share us the request and response logs in the same post? To the best of my knowledge, I'm not aware of anything that changes the specification of the request in v15, so I need to compare the results between two versions.

If possible, please share the whole request and response logs too. Thanks.

fiboknacky commented 6 months ago

Closing due to inactivity.

matteoc99 commented 6 months ago

I had the same error, and nothing proposed seemed to work. All packages where up to date: googleads/google-ads-php:22.0 google/gax:1.27

the solution was removing: ->withLinkedCustomerId while building the client

which was either unnecessary/redundant or used wrongly on my end, and the api started complaining starting with version 15.

DorsetDevStudio commented 6 months ago

Closing due to inactivity.

So you fixed it then ?

DorsetDevStudio commented 6 months ago

I had the same error, and nothing proposed seemed to work. All packages where up to date: googleads/google-ads-php:22.0 google/gax:1.27

the solution was removing: ->withLinkedCustomerId while building the client

which was either unnecessary/redundant or used wrongly on my end, and the api started complaining starting with version 15.

will try this.

DorsetDevStudio commented 6 months ago

I had the same error, and nothing proposed seemed to work. All packages where up to date: googleads/google-ads-php:22.0 google/gax:1.27

the solution was removing: ->withLinkedCustomerId while building the client

which was either unnecessary/redundant or used wrongly on my end, and the api started complaining starting with version 15.

THIS WORKS, thank you, just commented out this line and it started working again. Thank you.

image