I want to connect -any- customer Google AdWords Account with Google Login. (Like Wordstream)

I prepared a code, but there is a problem somewhere, I can't run it.

When the customer press the connect button, the screen appears. It says "XXX wants to acces your Google Account", it is approved but I cannot receive data.

How can i get datas from customer's account?

Code:

require 'google-api/vendor/autoload.php'; use Google\Auth\OAuth2; use Google\AdsApi\AdWords\AdWordsServices; use Google\AdsApi\AdWords\AdWordsSessionBuilder; use Google\AdsApi\AdWords\v201809\cm\CampaignService; use Google\AdsApi\Common\OAuth2TokenBuilder; session_start(); $oauth2 = new OAuth2([          'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',     'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',     'redirectUri' => 'https://xxxxx.xxxxxx',     'clientId' => 'xxxxxxxxx.apps.googleusercontent.com',     'clientSecret' => 'xxxxxxxxxxx',     'scope' => 'https://www.googleapis.com/auth/adwords',     'refresh_token' => 'xxxxxxxxxx' ]); if(!isset($_GET['code'])){          $oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));     $_SESSION['oauth2state'] = $oauth2->getState();     $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();     $refreshToken = $authToken['refresh_token'];          $path = "xxxxx/google-api/vendor/adsapi_php.ini";     $session = (new AdWordsSessionBuilder())         ->fromFile($path)         ->withOAuth2Credential($oauth2)         ->build();          $adWordsServices = new AdWordsServices();          $campaignService = $adWordsServices->get($session, CampaignService::class);          print_r($campaignService); } 

Tag:google-ads-api, google-signin

Add a new comment.