Hello. I'm having some trouble accepting a sent MCC link invitation with PHP.
The MCC account is not the top-level account, it is a sub MCC. I can send the invitation correctly (from account 9547216945 to client 1096054675) usign the API, the problem is when I use Oauth2 to access on behalf of that client and try to accept the invitation. Supose I have sent the invitation with no problem. I'm doing test using an Adwords account of my own, so that is my test client. Then I follow next steps to accept: ################################################################################# #File: test.php ################################################################################# $clientId = "834249844................ak68sd6t.apps.googleusercontent.com"; $clientSecret = "uJdPPC..............CN"; $callbackUrl = "http://mysite.com/test.php"; $oauth2 = new OAuth2([ 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirectUri' => $callbackUrl, 'clientId' => $clientId, 'clientSecret' => $clientSecret, 'scope' => 'https://www.googleapis.com/auth/adwords', ]); if (!isset($_GET['code'])) { $oauth2->setState(sha1(openssl_random_pseudo_bytes(1024))); $_SESSION['oauth2state'] = $oauth2->getState(); // Redirect the user to the authorization URL. $config = [ 'access_type' => 'offline', 'prompt' => 'consent']; header('Location: ' . $oauth2->buildFullAuthorizationUri($config)); exit; } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state.'); } else { $oauth2->setCode($_GET['code']); $authToken = $oauth2->fetchAuthToken(); $oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId($clientId) ->withClientSecret($clientSecret) ->withRefreshToken($authToken['refresh_token']) ->build() ; // Construct an API session configured from the OAuth2 credentials above. $session = (new AdWordsSessionBuilder()) ->withDeveloperToken("m2l..........Vq3g") ->withOAuth2Credential($oAuth2Credential) ->withClientCustomerId("1096054675") ->build() ; $adWordsServices = new AdWordsServices(); $linkOp = new LinkOperation(); $link = new ManagedCustomerLink(); $link->setClientCustomerId('1096054675'); $link->setManagerCustomerId('9547216945'); $link->setLinkStatus(LinkStatus::ACTIVE); $linkOp->setOperand($link); $linkOp->setOperator(Operator::ADD); $managedCustomerService = $adWordsServices->get($session, ManagedCustomerService::class); $result = $managedCustomerService->mutateLink([$linkOp]); } ################################################################################# That script makes me login into the client account (the one that I'm using for testing purpose), then I use that client refresh token with Oauth2, and when I want to accept the previous sent invitation, I get this error: [ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]] I tried to make it work multiple times with no success, anyone know what I'm doing wrong here? Thank you! -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ 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 [email protected] To unsubscribe from this group, send email to [email protected] 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 [email protected]. 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/4f0d1a42-a339-457a-b93e-5383bbdb45a1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
