I am using the Google Oauth2 API to connect to Google Ads and become only one refresh token when my @gmail.com account has read access to two different Google Ads accounts.
I have the account [email protected]. This account has read access to the Google Ads accounts [email protected] and [email protected].
When I create two connections to Google Ads with the email [email protected] for the accounts [email protected] and [email protected], then I receive only one refresh token, for the first connection and none refresh token for the second connection. Why? How can I manage this, to become 2 refresh tokens for each connection? The only way to become a refresh token for the second connection is to go to my account [email protected] and to decline the access to my app manually and connect again with [email protected]. But then [email protected] has no refresh token anymore.
code:
$oauth2 = new OAuth2(
[
'authorizationUri' => $this->container->getParameter('oauth2.google.adwords.authorizationUri'),
'tokenCredentialUri' => $this->container->getParameter('oauth2.google.adwords.tokenCredentialUri'),
'redirectUri' => $this->container->getParameter('domain.system') . $this->container->getParameter(
'oauth2.google.adwords.redirectUri.advertiser'
),
'clientId' => $this->container->getParameter('oauth2.google.adwords.clientId'),
'clientSecret' => $this->container->getParameter('oauth2.google.adwords.clientSecret'),
'scope' => $this->container->getParameter('oauth2.google.adwords.scope')
]
);
// Create a 'state' token to prevent request forgery.
// Store it in the session for later validation.
$randomState = sha1(openssl_random_pseudo_bytes(1024)) . '---' . $accountId;
$oauth2->setState($randomState);
// Redirect the user to the authorization URL.
$config = [
// Set to 'offline' if you require offline access.
'access_type' => 'offline',
'approval_prompt' => 'force'
];
// redirect to google ads
return new RedirectResponse($oauth2->buildFullAuthorizationUri($config));