// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId(self::MANAGER_CLIENT_ID)
->withClientSecret(self::MANAGER_CLIENT_SECRET)
->withRefreshToken(self::MANAGER_REFRESH_TOKEN)
->build();
// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session = (new AdWordsSessionBuilder())
->withOAuth2Credential($oAuth2Credential)
->withDeveloperToken(self::MANAGER_DEV_TOKEN)
->withClientCustomerId(self::MANAGER_CLIENT_CUSTOMER_ID)
->build();
$adWordsServices = new AdWordsServices();
/**
* @var ManagedCustomerService $managedCustomerService
*/
$managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);
$linkOp = new LinkOperation();
$link = new ManagedCustomerLink();
$link->setClientCustomerId(self::CLIENT_CID);
$link->setLinkStatus(LinkStatus::PENDING);
$link->setManagerCustomerId(self::MANAGER_CLIENT_CUSTOMER_ID);
$linkOp->setOperand($link);
$linkOp->setOperator(Operator::ADD);
$mutateLinkResults = $managedCustomerService->mutateLink([$linkOp]);
return $mutateLinkResults;