public static function runExample(GoogleAdsClient $googleAdsClient,$authorizationCode){
// dd($authorizationCode);
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
// dd($customerServiceClient);
// Create an array of optional arguments
$optionalArgs = [];
// Issues a request for listing all accessible customers.
try {
$accessibleCustomers = $customerServiceClient->listAccessibleCustomers();
} catch (Exception $e) {
dd($e);
}
// Create an array to store account names
$accountNames = [];
// Iterates over all accessible customers' resource names.
foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
// Extract the customer ID from the resource name.
$parts = explode('/', $resourceName);
$customerId = end($parts);
$accountNames[]=$customerId;
}
dd($accountNames);
// Dump the array containing account names.
foreach ($accountNames as $id) {
if ($id == 6444085743) {
$query = "SELECT
customer.descriptive_name
FROM customer";
$streamRequest = $googleAdsClient->getGoogleAdsServiceClient()->searchStream($id, $query);
foreach ($streamRequest->iterateAllElements() as $element) {
// Extract data from each result element.
$customerId = $element->getCustomer()->getId();
$descriptiveName = $element->getCustomer()->getDescriptiveName();
// Do something with the data, such as printing or storing it.
// dd("Customer ID: $customerId, Descriptive Name: $descriptiveName");
$contas = self::getCustomerAccounts($googleAdsClient,$customerId);
foreach ($contas as $account) {
$accountId = $account->getClientCustomer();
$accountName = $account->getDescriptiveName();
// Do something with the account data, such as printing or storing it.
dd("Customer ID: $customerId, Account ID: $accountId, Account Name: $accountName");
}
}
}
}
dd($accountNames);
} public static function runExample(GoogleAdsClient $googleAdsClient,$authorizationCode){
// dd($authorizationCode);
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
// dd($customerServiceClient);
// Create an array of optional arguments
$optionalArgs = [];
// Issues a request for listing all accessible customers.
try {
$accessibleCustomers = $customerServiceClient->listAccessibleCustomers();
} catch (Exception $e) {
dd($e);
}
// Create an array to store account names
$accountNames = [];
// Iterates over all accessible customers' resource names.
foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
// Extract the customer ID from the resource name.
$parts = explode('/', $resourceName);
$customerId = end($parts);
$accountNames[]=$customerId;
}
dd($accountNames);
// Dump the array containing account names.
foreach ($accountNames as $id) {
if ($id == 6444085743) {
$query = "SELECT
customer.descriptive_name
FROM customer";
$streamRequest = $googleAdsClient->getGoogleAdsServiceClient()->searchStream($id, $query);
foreach ($streamRequest->iterateAllElements() as $element) {
// Extract data from each result element.
$customerId = $element->getCustomer()->getId();
$descriptiveName = $element->getCustomer()->getDescriptiveName();
// Do something with the data, such as printing or storing it.
// dd("Customer ID: $customerId, Descriptive Name: $descriptiveName");
$contas = self::getCustomerAccounts($googleAdsClient,$customerId);
foreach ($contas as $account) {
$accountId = $account->getClientCustomer();
$accountName = $account->getDescriptiveName();
// Do something with the account data, such as printing or storing it.
dd("Customer ID: $customerId, Account ID: $accountId, Account Name: $accountName");
}
}
}
}
dd($accountNames);
}