Package Data | |
---|---|
Maintainer Username: | nikolajlovenhardt |
Maintainer Contact: | nikolaj.lovenhardt@gmail.com (Nikolaj Petersen) |
Package Create Date: | 2015-12-15 |
Package Last Update: | 2022-08-18 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:04:40 |
Package Statistics | |
---|---|
Total Downloads: | 90,666 |
Monthly Downloads: | 33 |
Daily Downloads: | 0 |
Total Stars: | 64 |
Total Watchers: | 18 |
Total Forks: | 58 |
Total Open Issues: | 5 |
Integration of googleads/googleads-php-lib
in Laravel and Lumen (version >5).
$ composer require spotonlive/laravel-google-ads
'providers' => [
LaravelGoogleAds\LaravelGoogleAdsProvider::class,
],
$ php artisan vendor:publish
to publish the configuration file config/google-ads.php
and insert:
bootstrap/app.php
$app->register(LaravelGoogleAds\LaravelGoogleAdsProvider::class);
Copy vendor/spotonlive/laravel-google-ads/config/config.php
to config/google-ads.php
and insert:
Add config to bootstrap/app.php
$app->configure('google-ads');
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
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);
}
}
See googleads/googleads-php-lib
googleads/googleads-php-lib
hosts the PHP client library for the various SOAP-based Ads APIs (AdWords, AdExchange Buyer, and DFP) at Google.