How can get customer_id by google-ads-php

1,176 views
Skip to first unread message

xiaozhe qi

unread,
Aug 17, 2023, 12:08:07 AM8/17/23
to Google Ads API and AdWords API Forum
The language I use is PHP,
Thank you very much for reading.
My requirement is to obtain the relevant data of the customer's advertising account through authorized ads after logging in through Oauth 2. We may have N customers, which is irrelevant. The problem I am currently facing is that I have already programmed the customer to complete the authorized login of Oauth 2[“ https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile I only received 'access'_ Token "and" id_token ", but now I have checked the documents and they all need to obtain relevant data through a customer_id. I have read the official Google ads API document and it is difficult for me to evaluate whether this document has been helpful to me. I now need to know how to obtain the customer's customer_id. 

The following is my relevant code:

Oauth v2 Code .
use Google\Client;

$redirect_uri = 'http://localhost:8000/google/callback';
$httpClient = new \GuzzleHttp\Client([
'proxy' => '*.*.*.*:7890',
'verify' => false,
]);
$client = new Client();
$client->setHttpClient($httpClient);
$client->setAuthConfig(base_path() . '/keys/google_secret.json');
$client->setRedirectUri($redirect_uri);
$client->setAccessType('offline');
$client->addScope(
 [
 ]
);

if (!$request->get('code')) {
 $authUrl = $client->createAuthUrl();
 return response()->redirectTo($authUrl);
} else {
 $code = $request->get('code');
 $client->authenticate($code);
 $access_token = $client->getAccessToken();
 //....... 
}

Google Ads API Forum Advisor

unread,
Aug 17, 2023, 4:37:57 AM8/17/23
to babaizh...@gmail.com, adwor...@googlegroups.com

Hi Xiaozhe,

 

Thank you for reaching out to the Google Ads API Support Team.

 

The customer ID is the account number of the Google Ads account you want to manage with the API, usually in the form 123-456-7890. You can check this link <https://developers.google.com/google-ads/api/docs/first-call/overview> from our documentation under Client customer ID for reference.

 

Additionally, you can use this code example <https://developers.google.com/google-ads/api/docs/account-management/listing-accounts#php> as it illustrates the use of the CustomerService.ListAccessibleCustomers method <https://developers.google.com/google-ads/api/reference/rpc/v14/CustomerService#listaccessiblecustomers>. Kindly note that it will only include accounts where your authenticated user has been added with admin or other rights in the account.

 

If you have any clarifications regarding the Google Ads API, just let us know.

 

This message is in relation to case "ref:_00D1U1174p._5004Q2ntGLT:ref"

Thanks,
 
Google Logo Google Ads API Team


xiaozhe qi

unread,
Aug 17, 2023, 11:54:32 PM8/17/23
to Google Ads API and AdWords API Forum
Hi ,
I am in China, and when I execute this code, it cannot return normally. Its error response is execution timeout. Perhaps I should set up a proxy? But I have already set up a proxy in 'google_ads_php.ini', but it doesn't seem to be taking effect.

my config "google_ads_php.ini" file contents.


[LOGGING]
; Optional logging settings.
; logFilePath = "path/to/your/file.log"
; logLevel = "INFO"

[CONNECTION]
; Optional proxy settings to be used by requests.
; If you don't have username and password, just specify host and port.
proxy = "http://x.xxxxx.xxx.xxx:7890"
 

 And I also used it in my code.

$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile(base_path() . '/google_ads_php.ini')->build();

$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile(base_path() . '/google_ads_php.ini')
->withOAuth2Credential($oAuth2Credential)
->usingGapicV2Source(true)
->build();

And this a dump
Google\Ads\GoogleAds\Lib\V14\GoogleAdsClient {#371 ▼ // app\Http\Controllers\GoogleRelationController.php:30 -developerToken: "xxxxfIlxxTPxxxxxxxxx" -loginCustomerId: null -linkedCustomerId: null -endpoint: null -oAuth2Credential: Google\Auth\Credentials\UserRefreshCredentials {#361 ▶} -logger: Monolog\Logger {#368 ▶} -logLevel: "info" -proxy: "http://xxx.xxx.xxx.xxx:7890" -transport: null -grpcChannelIsSecure: true -useGapicV2Source: true -grpcChannelCredential: null -unaryMiddlewares: [] -streamingMiddlewares: [] -grpcInterceptors: [] }

When I execute here, it will timeout and it doesn't seem to be using proxy 


$customerServiceClient = $googleAdsClient->getCustomerServiceClient();

// Issues a request for listing all accessible customers.
$accessibleCustomers =
$customerServiceClient->listAccessibleCustomers(new ListAccessibleCustomersRequest());  


Error Message : Curl Maximum execution time of 60 seconds exceeded

在2023年8月17日星期四 UTC+8 16:37:57<Google Ads API Forum Advisor> 写道:

嗨晓哲,

 

感谢您联系 Google Ads API 支持团队。

 

客户 ID 是您要通过 API 管理的 Google Ads 帐号的帐号,通常采用 123-456-7890 格式。您可以从客户客户 ID 下的文档查看此链接 <https://developers.google.com/google-ads/api/docs/first-call/overview> 以供参考。

 

此外,您可以使用此代码示例 <https://developers.google.com/google-ads/api/docs/account-management/listing-accounts#php> 因为它说明了 CustomerService.ListAccessibleCustomers 方法<的使用 https://developers.google.com/google-ads/api/reference/rpc/v14/CustomerService#listaccessiblecustomers>.请注意,它仅包括已将经过身份验证的用户添加到帐户中具有管理员或其他权限的帐户。

 

如果您对 Google Ads API 有任何说明,请告诉我们。

 

此消息与案例“ref:_00D1U1174p._5004Q2ntGLT:ref”

有关,谢谢,

  谷歌标志 谷歌广告 API 团队


Google Ads API Forum Advisor

unread,
Aug 18, 2023, 4:08:23 AM8/18/23
to babaizh...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for the reply.

For our team to further check this and provide appropriate recommendations to you, could you please provide us with the complete API logs (request, response, and request ID) generated on your end?

Note that logs can be requested or provided to the developer handling the Google Ads API transactions when logging of the API requests has been enabled. You may check this specific guideline to enable PHP: https://developers.google.com/google-ads/api/docs/client-libs/php/logging

You may then send the requested logs 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.
 

Reply all
Reply to author
Forward
0 new messages