Aleksey Razbakov
Posted on July 30, 2020
5 steps guide how to use googleads-php-lib
If you already tried to follow Make Your First API Call and video with talk through instead of walkthrough of the steps and you felt confused and unclear, then this tutorial is for you!
Step 1. Create Manager Account
You must have a Google Ads Manager Account to apply for access to the API.
START USING MANAGER ACCOUNTS - https://adwords.google.com/um/MccStartNow.
This link will create an AdWords manager account.
This is the one you should use if you are going through the AdWords API Sign Up guide to request a developer token.
Manager Accounts cannot be created using the same email address as an existing Google Ads account.
You must therefore use an email address that hasn't already been associated with a Google Ads account to create your Manager Account.
Sign up for AdWords API access through your Manager Account.
Sign in, then navigate to TOOLS & SETTINGS > SETUP > API Center.
The API Center option will appear only for Google Ads Manager Accounts.
Get Developer token
Step 2. Generate Test Client Id
Create a test manager account
- Go to https://adwords.google.com/um/Welcome/?sf=mt
- Select NEW GOOGLE ADS ACCOUNT and then name the new account something like test-manager@mycompany.example.com
- To create a test account, you must have a Google account that is not already linked to your production manager account. Create a new Google account.
- Once your test manager account is established, you can proceed to make API calls against it. Use the production manager account's developer token when making requests againsts the test manager account.
- When requesting an OAuth2 refresh token, make sure you're logged in as the test manager account user (for example, test-manager@mycompany.example.com).
You should see "Test account" in right top corner.
Take number client id (number above email)
Step 3. Create credentials
- Open the Google API Console Credentials page.
- Click Select a project, then NEW PROJECT, and enter a name for the project, and optionally, edit the provided project ID. Click Create.
- On the Credentials page, select Create credentials, then OAuth client ID.
- You may be prompted to set a product name on the Consent screen; if so, click Configure consent screen, supply the requested information, and click Save to return to the Credentials screen.
- Select Desktop Application for the Application Type.
- Click Create.
- On the page that appears, copy the client ID and client secret to your clipboard, as you will need them when you configure your client library.
Step 4. Generate refresh token
Following API access using own credentials (installed application flow)
- Get GetRefreshToken.php from the
example
directory by following this section. - In a terminal, navigate to GetRefreshToken.php.
- Run this file via the command line and follow instructions:
Copy the following lines to your 'adsapi_php.ini' file:
clientId = "xxxx.apps.googleusercontent.com"
clientSecret = "L-xxxxxxx"
refreshToken = "1//xxxxx"
Step 5. Execute test call.
- Install the latest googleads-php-lib version using Composer:
composer require googleads/googleads-php-lib
- Move
adsapi_php.ini
to project folder. - Download GetCampaigns.php example.
- Change in that file
require
path to/vendor/autoload.php
- Execute
php GetCampaigns.php
There should be no errors.
Now you can move forward and implement Conversion tracking following official documentation and examples.
Please write down in comments below if it actually worked for you and if you have any questions. I spent around 3 days to figure out how to configure it just to make a first test call. Be careful with datetime format 😉
Posted on July 30, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.