简体   繁体   中英

Google Ads API PHP

I am trying to use a service account to connect with the Google Ads API.

At the momet my code looks like this:

$oAuth2Credential = (new OAuth2TokenBuilder())
        ->withJsonKeyFilePath(self::CREDENTIALS_FILE_PATH)
        ->withScopes('https://www.googleapis.com/auth/adwords')
        ->withImpersonatedEmail(IMPERSONATED_EMAIL)
        ->build();

    $googleAdsClient = (new GoogleAdsClientBuilder())
        ->withOAuth2Credential($oAuth2Credential)
        ->withDeveloperToken(DEVELOPER_TOKEN)
        ->build();
    $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();

    $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';
    $stream =
        $googleAdsServiceClient->searchStream(CUSTOMER_ID, $query);

In Google cloud I have created a project and a service account. The account is the same I have access to at Google Ads. Also I have set the Domain-Wide Delegation at Google Workspace, with this same account. In my opinion I did everything right, but I am getting this error:

在此处输入图像描述

I hope there's someone who can help me out.

Hy jol123, Service accounts in Google are more like normal user accounts. So for a normal user to access your Ads account, you would have to share access to that account with the user(using the user's email address).

The same thing has to be done for the service account. You have to go into the Google ads account you wish to access and share access with the service account "email" you are using.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM