Hi guys,
In one of my projects, I am trying to link a Manager account with a customer (My account) account but it throws following error:
Fatal error: Uncaught exception 'Google\AdsApi\AdWords\v201705\cm\ApiException' with message '[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]
I have manager account id 9663159860 and customerId 6694378287. In the first step, I am taking refresh token by following oauth2 steps and getting the customer ID. After that, I am passing the customerID in ManagedCustomerLink object but when I try to use mutateLink it throws the above error. Here is the code below which I have used assuming I have already set the refresh token of customer in ini file.
public static function runExample(AdWordsServices $adWordsServices,
AdWordsSession $session) {
//$campaignService = $adWordsServices->get($session, CampaignService::class);
$managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class);
$customer = new ManagedCustomerLink();
$customer->setManagerCustomerId("9663159860");
$customer->setClientCustomerId("6694378287");
$customer->setLinkStatus("PENDING");
// Create operation.
$operation = new LinkOperation();
$operation->setOperand($customer);
$operation->setOperator("ADD");
//$operation->OperationType = $OperationType;
$operations = array($operation);
echo '<pre>';
print_r($operations);
// Make the mutate request.
$result = $managedCustomerService->mutateLink($operations);
print_r($result);
exit;
}
I would appreciate anyone's help as I am stuck for several hours here.
Thanks,
Amrender
$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);
$result = $managedCustomerService->mutateLink($operations);