spotonlive/laravel-google-ads
| Install | |
|---|---|
composer require spotonlive/laravel-google-ads |
|
| Latest Version: | 2.1 |
| PHP: | >=5.5.9 |
| Laravel: | 5 – 8 |
| License: | MIT |
| Last Updated: | Aug 18, 2022 |
| Links: | GitHub · Packagist |
Google Ads API for Laravel
Integration of googleads/googleads-php-lib in Laravel and Lumen (version >5).
Setup
- Run
$ composer require spotonlive/laravel-google-ads
Laravel
- (Only for Laravel 5.4 or minor) Add provider to config/app.php
'providers' => [
LaravelGoogleAds\LaravelGoogleAdsProvider::class,
],
- Run
$ php artisan vendor:publishto publish the configuration fileconfig/google-ads.phpand insert:- developerToken
- clientId & clientSecret
- refreshToken
Lumen
- Add provider to
bootstrap/app.php
$app->register(LaravelGoogleAds\LaravelGoogleAdsProvider::class);
-
Copy
vendor/spotonlive/laravel-google-ads/config/config.phptoconfig/google-ads.phpand insert:- developerToken
- clientId & clientSecret
- refreshToken
-
Add config to
bootstrap/app.php
$app->configure('google-ads');
Generate refresh token
This requires that the clientId and clientSecret is from a native application.
Run $ php artisan googleads:token:generate and open the authorization url. Grant access to the app, and input the
access token in the console. Copy the refresh token into your configuration config/google-ads.php
Basic usage
The following example is for AdWords, but the general code applies to all products.
<?php
namespace App\Services;
use LaravelGoogleAds\Services\AdWordsService;
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201806\cm\CampaignService;
use Google\AdsApi\AdWords\v201806\cm\OrderBy;
use Google\AdsApi\AdWords\v201806\cm\Paging;
use Google\AdsApi\AdWords\v201806\cm\Selector;
class Service
{
/** @var AdWordsService */
protected $adWordsService;
/**
* @param AdWordsService $adWordsService
*/
public function __construct(AdWordsService $adWordsService)
{
$this->adWordsService = $adWordsService;
}
public function campaigns()
{
$customerClientId = 'xxx-xxx-xx';
$campaignService = $this->adWordsService->getService(CampaignService::class, $customerClientId);
// Create selector.
$selector = new Selector();
$selector->setFields(array('Id', 'Name'));
$selector->setOrdering(array(new OrderBy('Name', 'ASCENDING')));
// Create paging controls.
$selector->setPaging(new Paging(0, 100));
// Make the get request.
$page = $campaignService->get($selector);
}
}
Best practices
Features, requirements, support etc.
See googleads/googleads-php-lib
Dependencies
googleads/googleads-php-libhosts the PHP client library for the various SOAP-based Ads APIs (AdWords, AdExchange Buyer, and DFP) at Google.
Credits
Related Packages
Google Ads API for Laravel forked from nikolajlovenhardt/laravel-google-ads
Google api php client wrapper with Cloud Platform and Laravel support
GoogleOAuth2 adds to Laravel a service provider for Google OAuth 2.0 authenticat...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 2.1 | >=5.5.9 | ^5.0| | MIT | |
| 2.0 | >=5.5.9 | ^5.0| | MIT | |
| 1.2.12 | >=5.5.9 | ^5.1 | MIT | |
| 1.2.11 | >=5.5.9 | ^5.1 | MIT | |
| 1.2.10 | >=5.5.9 | ^5.1 | MIT | |
| 1.2.9 | >=5.5.9 | ^5.1 | MIT | |
| 1.2.8 | >=5.5.9 | ^5.1 | MIT | |
| 1.2.7 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.6 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.5 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.4 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.3 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.2 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.1 | >=5.5.9 | ~5.1 | MIT | |
| 1.2.0 | >=5.5.9 | ~5.1 | MIT | |
| 1.1.0 | >=5.5.9 | ~5.1 | MIT | |
| 1.0.0 | >=5.5.9 | ~5.1 | MIT |
Pre-releases (10)
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 0.1.1-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.1.0-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.8-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.7-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.6-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.5-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.4-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.3-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.2-beta | >=5.5.9 | ~5.1 | MIT | |
| 0.0.1-beta | >=5.5.0 | 5.* | MIT |