Google adwords error code 7 PERMISSION_DENIED

1,416 views
Skip to first unread message

Гордей Строкин

unread,
Aug 4, 2021, 6:54:39 AM8/4/21
to AdWords API and Google Ads API Forum
Hello, i try to migrate to new google ads api and try to make request. 
<?php

require 'vendor/autoload.php';

use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\V8\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V8\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V8\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V8\GoogleAdsServerStreamDecorator;
use Google\Ads\GoogleAds\V8\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V8\Services\GoogleAdsRow;
use Google\ApiCore\ApiException;
ini_set('memory_limit', '700M');
$devToken = "my_dev_token";
$refreshToken = "my_refresh_token";
$clientId = "my_client_id";
$clientSecret = "my_client_secret";
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId($clientId)
->withClientSecret($clientSecret)
->withRefreshToken($refreshToken)
-> build();
$googleAdsClient = (new GoogleAdsClientBuilder())
    ->withDeveloperToken($devToken)
    ->withLoginCustomerId("my_login_customer_id")
    ->withOAuth2Credential($oAuth2Credential)
    ->build();
    runExample($googleAdsClient,"my_login_customer_id");
function runExample(GoogleAdsClient $googleAdsClient, int $customerId)
    {
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
        $stream =
            $googleAdsServiceClient->searchStream($customerId, $query);
        foreach ($stream->iterateAllElements() as $googleAdsRow) {
            printf(
                "Campaign with ID %d and name '%s' was found.%s",
                $googleAdsRow->getCampaign()->getId(),
                $googleAdsRow->getCampaign()->getName(),
                PHP_EOL
            );
        }
    }
?>
But i have an error like this 

 "message": "The caller does not have permission",

    "code": 7,

    "status": "PERMISSION_DENIED",

    "details": [

        {

            "@type": "google.ads.googleads.v8.errors.googleadsfailure-bin",

            "data": "<Unknown Binary Data>"

        },

        {

            "@type": "grpc-status-details-bin",

            "data": "<Unknown Binary Data>"

        },

        {

            "@type": "request-id",

            "data": "2mlrxVNlSUwrj7F9HjOwPg"

        }

    ]

}

Someone have an idea what to do ?

Google Ads API Forum Advisor

unread,
Aug 4, 2021, 11:18:11 PM8/4/21
to adwor...@googlegroups.com

Hi,

Thanks for reaching out to us. The PERMISSION_DENIED error usually occurs when there is no link between the manager account authenticated in the request and the client account specified in the headers. As you are using the Google Ads API you need to include the login-customer-id in the header as mentioned in this blog post. Please make sure you use the correct login-customer-id that you used to generate the OAuth2 credentials. 

To elaborate more on customer ID, if your access to the customer account is through a manager account (OAuth2 credentials created using a user that has access to your manager account), this header is required and must be set to the customer ID of the manager account. Since you’re using the PHP client library, then you will then need to specify this in your google_ads_php.ini file, where your other credentials are placed. Let us know if you have any further questions.

Regards,

Google Logo
Yasar
Google Ads API Team
 

 



ref:_00D1U1174p._5004Q2HLh4U:ref

Гордей Строкин

unread,
Aug 5, 2021, 10:06:45 AM8/5/21
to AdWords API and Google Ads API Forum
Sory, i cant resolve this problem, i dont use google_ads_php.ini because i get info from db, but in my first question i attached code and response and there are request id. May be you can check what is the problem with it ?

четверг, 5 августа 2021 г. в 06:18:11 UTC+3, adsapi:

Google Ads API Forum Advisor

unread,
Aug 6, 2021, 3:11:34 AM8/6/21
to adwor...@googlegroups.com

Hi,

Thanks for the clarification.

In order to avoid the Permission_denied error, you will need to ensure that the user / email address you used to generate the credentials indeed has access to the account in your request. If the user / email address has access or is associated to the MCC / manager account, you will need to specify the said MCC / manager account's ID as the value of the login-customer-id field.

If the issue persists, could you please share the following information so that our team can take closer look?

  • Customer ID
  • Provide us the user / email address it was you used when you generated your credentials
  • Provide us the complete request and response logs with the request-id


If you haven’t enabled logging yet, logging can be enabled by navigating to the Client libraries > Your client library (ex. PHP) > Logging documentation, which you can access from this link

You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Regards,

Reply all
Reply to author
Forward
0 new messages