{"id":24838,"date":"2022-03-14T11:21:51","date_gmt":"2022-03-14T11:21:51","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/blog\/?p=24838"},"modified":"2026-02-05T05:52:44","modified_gmt":"2026-02-05T05:52:44","slug":"integrate-google-adwords-api-in-laravel-app","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/blog\/integrate-google-adwords-api-in-laravel-app","title":{"rendered":"How to Integrate Google Adwords API in Laravel App?"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>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\u2019s when it struck us to come up with a tutorial for fellow Laravel developers.<\/p>\n<p>Without further ado, let\u2019s move ahead and see how to integrate <b>Google Adwords API in Laravel App<\/b>. <\/p>\n<h2>Required Package<\/h2>\n<p>We will be needing the following packages to integrate <i>Google Adwords API in Laravel App<\/i>.<\/p>\n<h3>googleads\/google-ads-php<\/h3>\n<p>PHP client library for the Google Adwords API.<\/p>\n<h3>ext-bcmath<\/h3>\n<p>BCMath is a PHP extension helping us with float values. BC is known for Binary Calculator in BCMath.<\/p>\n<h3>ext-grpc<\/h3>\n<p>The framework gRPC will be used for developing scalable APIs. It will lessen our struggle and allow transparent client-server communication and connected systems.<\/p>\n<h3>ext-protobuf<\/h3>\n<p>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.<\/p>\n<h3>Update composer.json with the following packages<\/h3>\n<pre>composer require googleads\/google-ads-php\r\ncomposer require ext-bcmath\r\ncomposer require ext-grpc\r\ncomposer require ext-protobuf<\/pre>\n<h2>Required PHP Extension<\/h2>\n<p>Make sure you have the following PHP modules in your system to integrate Google Adwords API.<\/p>\n<ul class=\"bullets text-left\">\n<li>Bcmatch<\/li>\n<li>Grpc<\/li>\n<li>Protobuf<\/li>\n<li>Soap<\/li>\n<\/ul>\n<p class=\"boxed bg--secondary\" style=\"border: 1px solid #c7c7c7; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);\"><strong><i><span style=\"font-size:22px; color:#000;\">Stop searching for the best Laravel developers. Because here we are!<\/span><br \/>\nBacancy will provide you proficient and dedicated developers with fundamental and advanced Laravel knowledge. Contact us to hire <a href=\"https:\/\/www.bacancytechnology.com\/hire-laravel-developer\" target=\"_blank\" rel=\"noopener\">Laravel developer<\/a> today!<\/i><\/strong><\/p>\n<h2>Generate client ID and client secret key<\/h2>\n<p>Follow these instructions to generate a client ID and client secret key. <\/p>\n<ul class=\"bullets text-left\">\n<li>Open the <a href=\"https:\/\/console.developers.google.com\/apis\/credentials\" target=\"_blank\" rel=\"noopener\"><strong>Google API Console Credentials page<\/strong><\/a>.<\/li>\n<li>Navigate the following path to create a project: <strong>Select a project > NEW PROJECT > Enter project\u2019s name OR Edit the provided project ID<\/strong>. Click Create.<\/li>\n<li>Select <strong>Create credentials<\/strong> and click on <strong>OAuth client ID<\/strong> on the Credentials page.<\/li>\n<li>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.<\/li>\n<li>Select the <strong>Application type<\/strong> and click Create<\/li>\n<li>Copy your client ID and client secret as you will be needing them for configuring your client library.<\/li>\n<\/ul>\n<h2>Enable Google Ads API<\/h2>\n<p>For using the Google Ads API we will need to enable it. So, follow these instructions to enable the Google Adwords API.<\/p>\n<ul class=\"bullets text-left\">\n<li>Open the <a href=\"https:\/\/console.developers.google.com\/apis\/credentials\" target=\"_blank\" rel=\"noopener\"><strong>Google API Console Credentials page<\/strong><\/a><\/li>\n<li>Navigate  to APIs &#038; Services -> Library<\/li>\n<li>Search for Google Ads API<\/li>\n<li>Open the Google Ads API library and enable it<\/li>\n<\/ul>\n<h2>Generate Developer Token<\/h2>\n<p>Without a developer token, you won\u2019t be able to proceed further. With the help of the below steps generate your developer token.<\/p>\n<ul class=\"bullets text-left\">\n<li>Login to <strong>Google Ads Manager account<\/strong><\/li>\n<li>Navigate to <strong>TOOLS &#038; SETTINGS > SETUP > API Center<\/strong>. The API Center option appears only for Google Ads manager accounts.<\/li>\n<li>Fill out the form to request a developer token.<\/li>\n<\/ul>\n<p><em>Note: Only approved developer token will be used for production. A non-approved developer token can only be used with a test account.<\/em><\/p>\n<h2>Generate Refresh Token<\/h2>\n<ul class=\"bullets text-left\">\n<li>Run <mark><strong>AuthenticateInDesktopApplication.php<\/strong><\/mark> or <mark><strong>AuthenticateInWebApplication.php<\/strong><\/mark> in the terminal.<\/li>\n<li>To run any of the above files go to path for file then php filename.<\/li>\n<\/ul>\n<h2>Fetch Data using Google Adwords API in Laravel App<\/h2>\n<p>So, far we are done with the initial project set up and generating a developer token for using Google Ads API. Now, let\u2019s do some coding.<\/p>\n<ul class=\"bullets text-left\">\n<li>Copy sample <a href=\"https:\/\/github.com\/googleads\/google-ads-php\/blob\/main\/examples\/Authentication\/google_ads_php.ini\" target=\"_blank\" rel=\"noopener\"><strong>google_ads_php.ini<\/strong><\/a> to home directory.<\/li>\n<li>Set google_ads_php.ini path in app config.<\/li>\n<\/ul>\n<pre>'google_ads_php_path' => realpath(base_path('google_ads_php.ini'))<\/pre>\n<ul class=\"bullets text-left\">\n<li>Register GoogleAdsClient in AppServiceProvider<\/li>\n<\/ul>\n<pre>use Google\\Ads\\GoogleAds\\Lib\\V9\\GoogleAdsClientBuilder;\r\nuse Google\\Ads\\GoogleAds\\Lib\\OAuth2TokenBuilder;\r\n\r\npublic function register()\r\n   {\r\n       \/\/ Binds the Google Ads API client.\r\n       $this->app->singleton('Google\\Ads\\GoogleAds\\Lib\\V9\\GoogleAdsClient', function () {\r\n           \/\/ Constructs a Google Ads API client configured from the properties file.\r\n           return (new GoogleAdsClientBuilder())\r\n               ->fromFile(config('app.google_ads_php_path'))\r\n               ->withOAuth2Credential((new OAuth2TokenBuilder())\r\n                   ->fromFile(config('app.google_ads_php_path'))\r\n               ->build())\r\n               ->build();\r\n       });\r\n   }\r\n<\/pre>\n<p><a href=\"https:\/\/www.bacancytechnology.com\/blog\/outsource-laravel-development\" target=\"_blank\" rel=\"noopener\">Outsource Laravel Development<\/a><\/p>\n<h2>Github Repository: Google Ads API Integration Demo<\/h2>\n<p>You can visit the source code: <a href=\"https:\/\/github.com\/khatrijigisha\/google-ads-demo\" target=\"_blank\" rel=\"noopener\">google-ads-api-demo<\/a> and play around with the code. <\/p>\n<h2>Conclusion<\/h2>\n<p>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. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction 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 [&hellip;]<\/p>\n","protected":false},"author":93,"featured_media":24852,"comment_status":"open","ping_status":"open","sticky":false,"template":"blog-new-template.php","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[1142],"tags":[],"coauthors":[1877],"class_list":["post-24838","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"acf":[],"modified_by":"Aditya Goswami","_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/24838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/users\/93"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=24838"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/24838\/revisions"}],"predecessor-version":[{"id":57532,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/24838\/revisions\/57532"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media\/24852"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=24838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=24838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=24838"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/coauthors?post=24838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}