This document provides steps to integrate the Google Adwords API into a Laravel application. It explains that the googleads/google-ads-php package needs to be installed via Composer along with PHP extensions like bcmath, grpc, and protobuf. It also outlines generating a client ID and secret, enabling the Google Ads API, generating a developer token, fetching data using the API, and includes a link to a GitHub repository with a demo project.
3. Have you encountered a requirement
where you need to implement Google Ads
API? If yes, and wondering how can you do
it then here is a blog for you! A few weeks
back, one of our developers had a
requirement for Google Adwords API
integration in the laravel application. And
searching for a proper tutorial was a real
struggle! That’s when it struck us to come
up with a tutorial for fellow Laravel
developers.
Without further ado, let’s move ahead and
see how to integrate Google Adwords API in
Laravel App.
5. We will be needing the following packages
to integrate Google Adwords API in
Laravel App.
googleads/google-ads-php
PHP client library for the Google Adwords
API.
ext-bcmath
BCMath is a PHP extension helping us
with float values. BC is known for Binary
Calculator in BCMath.
ext-grpc
The framework gRPC will be used for
developing scalable APIs. It will lessen our
struggle and allow transparent client-
server communication and connected
systems.
6. ext-protobuf
The protobuf implements Protocol Buffer
of Google for PHP language that supports
serialization of binary data and includes a
protoc plugun for generating classes from
.proto files.
Update composer.json
with the following
packages
composer require googleads/google-ads-
php
composer require ext-bcmath
composer require ext-grpc
composer require ext-protobuf
9. Stop searching for the best
Laravel developers.
Because here we are!
Bacancy will provide you proficient and
dedicated developers with fundamental
and advanced Laravel knowledge. Contact
us to hire Laravel developer today!
11. Open the Google API Console
Credentials page.
Navigate the following path to create a
project: Select a project > NEW
PROJECT > Enter project’s name OR
Edit the provided project ID. Click
Create.
Select Create credentials and click on
OAuth client ID on the Credentials page.
If prompted for setting the product
name on the Consent screen, click
Configure consent screen, provide the
information asked for, and click Save
and you will return to the Credentials
screen.
Follow these instructions to generate a
client ID and client secret key.
12. Select the Application type and click
Create
Copy your client ID and client secret as
you will be needing them for
configuring your client library.
14. Open the Google API Console
Credentials page
Navigate to APIs & Services -> Library
Search for Google Ads API
Open the Google Ads API library and
enable it
For using the Google Ads API we will need
to enable it. So, follow these instructions to
enable the Google Adwords API.
16. Login to Google Ads Manager account
Navigate to TOOLS & SETTINGS >
SETUP > API Center. The API Center
option appears only for Google Ads
manager accounts.
Fill out the form to request a developer
token.
Without a developer token, you won’t be
able to proceed further. With the help of the
below steps generate your developer token.
Note: Only approved developer token will
be used for production. A non-approved
developer token can only be used with a
test account.
18. Run AuthenticateInDesktop
To run any of the above files go to path
for file then php filename.
Application.php
or
AuthenticateInWebApplication.php in
the terminal.
20. Copy sample google_ads_php.ini to
home directory.
Set google_ads_php.ini path in app
config.
So, far we are done with the initial project
set up and generating a developer token
for using Google Ads API. Now, let’s do
some coding.
'google_ads_php_path' =>
realpath(base_path('google_ads_php.ini'))
21. Register GoogleAdsClient in
AppServiceProvider
use
GoogleAdsGoogleAdsLibV9GoogleAdsCl
ientBuilder; use
GoogleAdsGoogleAdsLibOAuth2TokenB
uilder; public function register() { // Binds
the Google Ads API client. $this->app-
>singleton('GoogleAdsGoogleAdsLibV9
GoogleAdsClient', function () { // Constructs
a Google Ads API client configured from the
properties file. return (new
GoogleAdsClientBuilder()) -
>fromFile(config('app.google_ads_php_pat
h')) ->withOAuth2Credential((new
OAuth2TokenBuilder()) -
>fromFile(config('app.google_ads_php_pat
h')) ->build()) ->build(); }); }
23. You can visit the source code: google-
ads-api-demo and play around with
the code.
24. Conclusion
I hope the tutorial on integrating Google
Adwords API in Laravel App was helpful to
you. If you have any questions or
suggestions feel free to contact us. For more
such tutorials, visit Laravel tutorials page
where you can clone the repository, start
exploring the code, and learn about more
Laravel.