Posts tagged with google-ads-api

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); } 

During checking traffic source on e-commerce website i get confused.

I know that param gclid=.. means that user is tagged by GoogleAds, while fbclid works the same way but with facebook.

However, I dont understand what does it mean while they are both together in single url, like: www.example.com?gclid=CjwKCAiAyrXiBRAjEiwATI95mafT26kwak0CFBgICH0ZlLqafSBuyyoUBVZihf22pPdG9QK8DUmiZBoCh8YQAvD_BwE&gclsrc=aw.ds&fbclid=IwAR0oihEZbw0Q43GXiv4YW9n_G9odTEcpxzLtMxjYYqgrTt5EM-BcKqrJyuU

Is it possible that google ads is displaying ads on facebook and that is why gclid and fbclid are attached to url at the same time?

When I run an ads-script to call the app-script::spreadsheet API, I get the following error:

var sheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL); var rangeValues = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues(); ==> Cannot find method getRange(number,number,number,number) 

How can it be? Only a subset of the app-script sheet api is available from ads-script?