Hello, Thank you for answer. namespace Google\AdsApi\Examples\Authentication;
require __DIR__ . '/vendor/autoload.php'; use GetOpt\GetOpt; use Google\Auth\CredentialsLoader; use Google\Auth\OAuth2; use Psr\Http\Message\ServerRequestInterface; use React\EventLoop\Factory; use React\Http\Response; use React\Http\Server; use UnexpectedValueException; use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames; use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser; use Google\Ads\GoogleAds\Lib\V1\GoogleAdsClient; use Google\Ads\GoogleAds\Lib\V1\GoogleAdsClientBuilder; use Google\Ads\GoogleAds\Lib\V1\GoogleAdsException; use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder; use Google\Ads\GoogleAds\V1\Errors\GoogleAdsError; use Google\Ads\GoogleAds\V1\Services\GoogleAdsRow; use Google\ApiCore\ApiException; use Google\Ads\GoogleAds\V1\Resources\Customer; use Google\Ads\GoogleAds\Util\V1\ResourceNames; session_start(); define("PAGE_SIZE", 100); $oauth2 = new OAuth2([ 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirectUri' => 'https://xxxxxxxxxxxxxx', 'clientId' => 'xxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com', 'clientSecret' => 'xxxxxxxxxxxxxxxxxxxxxx', 'scope' => array('https://www.googleapis.com/auth/adwords', 'https://www.googleapis.com/auth/content', 'https://www.googleapis.com/auth/siteverification') ]); if (!isset($_GET['code'])) { // Create a 'state' token to prevent request forgery. // Store it in the session for later validation. $oauth2->setState(sha1(openssl_random_pseudo_bytes(1024))); $_SESSION['oauth2state'] = $oauth2->getState(); // Redirect the user to the authorization URL. $config = [ // Set to 'offline' if you require offline access. 'prompt' => 'consent', 'access_type' => 'offline' ]; header('Location: ' . $oauth2->buildFullAuthorizationUri($config)); exit; }elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { // Check given state against previously stored one to mitigate CSRF attack. unset($_SESSION['oauth2state']); exit('Invalid state.'); } else { $oauth2->setCode($_GET['code']); $authToken = $oauth2->fetchAuthToken(); $refreshToken = $authToken['refresh_token']; //print_r($refreshToken); $_SESSION["refresh_token"] = $refreshToken; $googleAdsClient = (new GoogleAdsClientBuilder())->fromFile() ->withOAuth2Credential($oauth2) ->build(); $customerServiceClient = $googleAdsClient->getCustomerServiceClient(); // Issues a request for listing all accessible customers. $accessibleCustomers = $customerServiceClient->listAccessibleCustomers(); print 'Total results: ' . count($accessibleCustomers) . PHP_EOL; // Iterates over all accessible customers' resource names and prints them. foreach ($accessibleCustomers->getResourceNames() as $resourceName) { /** @var string $resourceName */ // printf("Customer resource name: '%s'%s", $resourceName, PHP_EOL); $customerId = explode("/", $resourceName); $customerId = $customerId[1]; } /* This returns an empty result. */ $customer = $customerServiceClient->getCustomer(ResourceNames::forCustomer('xxxxxxxxx')); // Print information about the account. printf( "Customer with ID %d, descriptive name '%s', currency code '%s', timezone '%s', " . "tracking URL template '%s' and auto tagging enabled '%s' was retrieved.%s", $customer->getId()->getValue(), $customer->getDescriptiveName()->getValue(), $customer->getCurrencyCode()->getValue(), $customer->getTimeZone()->getValue(), $customer->getTrackingUrlTemplate()->getValue(), $customer->getAutoTaggingEnabled()->getValue() ? 'true' : 'false', PHP_EOL ); понедельник, 8 апреля 2019 г., 20:53:52 UTC+2 пользователь Непомнющий Александр написал: > > Введите код... > > Hi, > > when we create a Customer, we specify a 'descriptive_name'. How to get > this field, knowing Client Id? > > // Iterates over all accessible customers' resource names and > prints them. > foreach ($accessibleCustomers->getResourceNames() as > $resourceName) { > /** @var string $resourceName */ > // printf("Customer resource name: '%s'%s", $resourceName, > PHP_EOL); > $customerId = explode("/", $resourceName); > $customerId = $customerId[1]; > > } > > > -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog: https://googleadsdeveloper.blogspot.com/ =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/adwords-api?hl=en --- You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/adwords-api. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/41d27f81-a93e-428e-b36f-b3c4f47602cd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.