googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
294 stars 262 forks source link

Not receiving refresh token (for AuthenticateInWebApplication) #505

Closed thearyanahmed closed 3 years ago

thearyanahmed commented 3 years ago

I'm implementing the oauth2. Scopes are set for both adwords and admanager.

But unfortunately, I'm not getting any refreshToken.


After approving the application, enter the authorization code here: ********LtUEbxif-UgdkifQF-QL-IF_73CozLturK6__CxfNXP8Q5YNV7IqFtJMQ

PHP Warning:  Undefined array key "refresh_token" in /Users/prophecy/Desktop/sites/jdlx-boiler/GetRefreshToken.php on line 128

Warning: Undefined array key "refresh_token" in /Users/prophecy/Desktop/sites/jdlx-boiler/GetRefreshToken.php on line 128
Your refresh token is:

PHP Warning:  Undefined array key "refresh_token" in /Users/prophecy/Desktop/sites/jdlx-boiler/GetRefreshToken.php on line 135

Warning: Undefined array key "refresh_token" in /Users/prophecy/Desktop/sites/jdlx-boiler/GetRefreshToken.php on line 135
Copy the following lines to your 'adsapi_php.ini' file:
clientId = "clientid"
clientSecret = "secret"
refreshToken = ""

image

I've tried both examples,

my code


   public function setup() {
 //      Google\Auth\OAuth2;

        $this->oauth2 = new OAuth2(
            [
                'authorizationUri' => self::AUTHORIZATION_URI,
                'redirectUri' => $this->redirectURI,
                'tokenCredentialUri' => CredentialsLoader::TOKEN_CREDENTIAL_URI,
                'clientId' => $this->clientID,
                'clientSecret' => $this->clientSecret,
                'scope' => $scopes
            ]
        );
    }

    public function getOauthUrl()
    {
        return sprintf("%s",$this->oauth2->buildFullAuthorizationUri());
    }

    public function authorize(string $code)
    {
        $this->oauth2->setCode($code);
        return $this->oauth2->fetchAuthToken();
    }
thearyanahmed commented 3 years ago

The response I get

{
  "access_token": "a-access-token",
  "expires_in": 3591,
  "scope": "https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/dfp",
  "token_type": "Bearer"
}

The refresh token is not present.

fiboknacky commented 3 years ago

Please find an issue here. This library is for the Google Ads API, not the AdWords API and Ad Manager. Thank you.