function Auth() { session_start();
$oauth2 = new OAuth2([ 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirectUri' => '***************', 'clientId' => '***************', 'clientSecret' => '***************', 'scope' => 'https://www.googleapis.com/auth/adwords' ]); 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. 'access_type' => 'offline' ]; header('Location: ' . $oauth2->buildFullAuthorizationUri($config)); exit; } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state.'); } else { $d = $oauth2->setCode($_GET['code']); $authToken = $oauth2->fetchAuthToken(); $oAuth2Credential = (new OAuth2TokenBuilder()) ->fromFile() ->build(); $session = (new AdWordsSessionBuilder()) ->fromFile() ->withOAuth2Credential($oAuth2Credential) ->build(); $adWordsServices = new AdWordsServices(); $campaignService = $adWordsServices->get($session, CampaignService::class); define('PAGE_LIMIT',500); // Create selector. $selector = new Selector(); $selector->setFields(['Id', 'Name']); $selector->setOrdering([new OrderBy('Name', SortOrder::ASCENDING)]); $selector->setPaging(new Paging(0, PAGE_LIMIT)); $totalNumEntries = 0; do { // Make the get request. $page = $campaignService->get($selector); // Display results. if ($page->getEntries() !== null) { $totalNumEntries = $page->getTotalNumEntries(); foreach ($page->getEntries() as $campaign) { printf( "Campaign with ID %d and name '%s' was found.\n", $campaign->getId(), $campaign->getName() ); } } // Advance the paging index. $selector->getPaging()->setStartIndex( $selector->getPaging()->getStartIndex() + PAGE_LIMIT ); } while ($selector->getPaging()->getStartIndex() < $totalNumEntries); printf("Number of results found: %d\n", $totalNumEntries); } n response, "Message: [AuthorizationError.USER_PERMISSION_DENIED @; trigger: ']" It may be possible to find some other solution to get a list of the user's companies and statistics on these companies using the OAuth2 token -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and Google+: https://googleadsdeveloper.blogspot.com/ https://plus.google.com/+GoogleAdsDevelopers/posts =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords 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 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/7daf0a9c-4014-451f-968a-40e37e525d83%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.