$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build(); $session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->enablePartialFailure()->build();
$adWordsServices=new AdWordsServices(); $managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);
$link = new ManagedCustomerLink(); $link->setManagerCustomerId($managerid); $link->setClientCustomerId($customerid); $link->setLinkStatus(LinkStatus::PENDING);
$linkop = new LinkOperation(); $linkop->setOperator(Operator::ADD); $linkop->setOperand($link);
$operations = array($linkop); try{ $result = $managedCustomerService->mutateLink($operations); }catch(AdwordsApiException $e){ print_r($e); print_r($result->getPartialFailureErrors()); }catch(Exception $e){ print_r($e); print_r($result->getPartialFailureErrors()); }catch(ApiException $e){ print_r($e); print_r($result->getPartialFailureErrors()); }
Fatal error: Uncaught exception
'Google\AdsApi\AdWords\v201708\cm\ApiException' with message
'[ManagedCustomerServiceError.ALREADY_INVITED_BY_THIS_MANAGER @
operations[0]]' in
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php:39
Stack trace:
#0
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php(39):
ReflectionClass->newInstanceArgs(Array)
#1
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(165):
Google\AdsApi\Common\Util\Reflection->createInstance('Google\AdsApi\A...',
'[ManagedCustome...')
#2
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(130):
Google\AdsApi\Common\AdsSoapClient->parseApiExceptionFromSoapFault(Object(SoapFault))
#3
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/v201708/mcm/ManagedCustomerService.php(185):
Google\AdsApi\Common\AdsSoapClient->__soapCall('mutateLink', Array
in /var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php on line 39
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
// Construct an API session configured from a properties file and the OAuth2 credentials above. $session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->withClientCustomerId($customerid)->build();
$adWordsServices=new AdWordsServices();
Fatal error: Uncaught exception
'Google\AdsApi\AdWords\v201708\cm\ApiException' with message
'[AuthorizationError.USER_PERMISSION_DENIED @ ; trigger:'<null>']'
in
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php:39
Stack trace:
#0
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php(39):
ReflectionClass->newInstanceArgs(Array)
#1
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(165):
Google\AdsApi\Common\Util\Reflection->createInstance('Google\AdsApi\A...',
'[AuthorizationE...')
#2
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/AdsSoapClient.php(130):
Google\AdsApi\Common\AdsSoapClient->parseApiExceptionFromSoapFault(Object(SoapFault))
#3
/var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/AdWords/v201708/cm/CampaignService.php(158):
Google\AdsApi\Common\AdsSoapClient->__soapCall('get', Array)
#4 /var/www/adwords_api/Ge in /var/www/adwords_api/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/Util/Reflection.php on line 39
namespace Google\AdsApi\Examples\AdWords\v201708\BasicOperations;ini_set("display_errors",1);require __DIR__ . '/vendor/autoload.php';use Google\AdsApi\AdWords\AdWordsServices;use Google\AdsApi\AdWords\AdWordsSession;use Google\AdsApi\AdWords\AdWordsSessionBuilder;use Google\AdsApi\AdWords\v201708\cm\CampaignService;use Google\AdsApi\AdWords\v201708\cm\OrderBy;use Google\AdsApi\AdWords\v201708\cm\Paging;use Google\AdsApi\AdWords\v201708\cm\Predicate;use Google\AdsApi\AdWords\v201708\cm\PredicateOperator;use Google\AdsApi\AdWords\v201708\cm\Selector;use Google\AdsApi\AdWords\v201708\cm\SortOrder;use Google\AdsApi\Common\OAuth2TokenBuilder;
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$error=false; try{ $session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->withClientCustomerId($customerid)->enablePartialFailure()->build(); } catch(ApiException $apiException) { print_r($apiException); }
$adWordsServices=new AdWordsServices(); $campaignService = $adWordsServices->get($session, CampaignService::class);
$selector = new Selector(); $Fields = array('Id', 'StartDate', 'EndDate', 'Name', 'Amount', 'DeliveryMethod', 'ServingStatus', 'FrequencyCapMaxImpressions', 'AdServingOptimizationStatus', 'TimeUnit', 'Level', 'Status', 'BiddingStrategyType'); $selector->setFields($Fields); $selector->setOrdering([new OrderBy('Name', SortOrder::ASCENDING)]); $selector->setPaging(new Paging(0, 5000)); $totalNumEntries = 0; $icount=0;
$selector->setPredicates([new Predicate('Status', PredicateOperator::IN, ['ENABLED', 'PAUSED', 'REMOVED'])]);
$page = $campaignService->get($selector);
try{ $page = $campaignService->get($selector); } catch (ApiException $apiException) { print_r($apiException); }
try{
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$result = $this->EstimateKeywordTraffic(new AdWordsServices(), $session);
}
catch (ApiException $apiException) {
print_r($apiException);
}