How To Integrate Google Adwords Api Into Codeigniter?
One blogger gave me reckon
After many hours of searching, reading in addition to testing I was successful to integrate AdWords API PHP Client Library into Codeigniter 2.X.
Step yesteryear footstep conduct on how to integrate Google Adwords API into Codeigniter.
Set the right path on application/libraries/My_adwords.php
Just add together all the api documents to the third_party folder in addition to ask the library from your controller or library in addition to voilĂ !
Figure: Google Adwords API Hierarchy |
After many hours of searching, reading in addition to testing I was successful to integrate AdWords API PHP Client Library into Codeigniter 2.X.
Step yesteryear footstep conduct on how to integrate Google Adwords API into Codeigniter.
# | Steps | Description |
---|---|---|
1. | Download AdWords API PHP Client Library | This customer library makes it easier to write PHP applications that programmatically access the AdWords API or DoubleClick Ad Exchange Buyer API. I accept downloaded version 4.5.1(adwords_api_php_4.5.1) |
2. | Extract the compressed archive (.zip or .tar.gz) in addition to glue the src folder within codeigniter's third_party folder. | Grab solely src folder from the compressed files. Create a folder called Adwords within CodeIgniter’s application/third_party/ in addition to glue src folder within CodeIgniter’s application/third_party/Adwords/ folder. Your application/third_party/ folder volition await similar application/third_party/Adwords/src/... |
3. | Create a php file within Codeigniter's library folder. | Create novel PHP file within Codeigniter’s application/libraries/ advert it My_adwords.php |
4. | Set the right path to access Adwords API. | Check the rootage code below on how to gear upward the right path on application/libraries/My_adwords.php. I accept added GetCampaigns purpose (copied from Example folder of google adwords php customer library) to depository fiscal establishment stand upward for afterwards if it returns whatever values. |
5. | Now yous tin work My_Adwords library inwards your CodeIgniter’s controller code. | Now yous tin easily access the My_Adwords library from the Codeigniter's controller similar whatever other library methods. I accept created a controller called adwords.php within application/controller/ in addition to telephone phone the purpose to fetch all the active campaigns. You tin larn the rootage of controller adwords.php |
6. | Test the controller in addition to enjoy. | Type the 'localhost/your_project_folder/adwords/' inwards your browser in addition to yous tin run across the result. You tin run across my outcome inwards the end. |
Set the right path on application/libraries/My_adwords.php
<?php if (!defined('BASEPATH')) exit('No at 1 time script access allowed'); define('SRC_PATH', APPPATH.'/third_party/Adwords/src/'); define('LIB_PATH', 'Google/Api/Ads/AdWords/Lib'); define('UTIL_PATH', 'Google/Api/Ads/Common/Util'); define('AW_UTIL_PATH', 'Google/Api/Ads/AdWords/Util'); define('ADWORDS_VERSION', 'v201306'); // Configure include path ini_set('include_path', implode(array( ini_get('include_path'), PATH_SEPARATOR, SRC_PATH)) ); // Include the AdWordsUser file require_once SRC_PATH.LIB_PATH. '/AdWordsUser.php'; flat My_adwords extends AdWordsUser { world purpose __construct() { parent::__construct(); } purpose GetCampaigns() { // Get the service, which loads the required classes. $campaignService = $this->GetService('CampaignService', ADWORDS_VERSION); // Create selector. $selector = novel Selector(); $selector->fields = array('Id', 'Name'); $selector->ordering[] = novel OrderBy('Name', 'ASCENDING'); // Create paging controls. $selector->paging = novel Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); exercise { // Make the larn request. $page = $campaignService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries every bit $campaign) { printf("Campaign amongst advert '%s' in addition to ID '%s' was found.\n", $campaign->name, $campaign->id); } } else { impress "No campaigns were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } patch ($page->totalNumEntries > $selector->paging->startIndex); } }source code: application/controllers/adwords.php
<?php error_reporting(E_STRICT | E_ALL); ini_set('display_errors', '1'); if ( ! defined('BASEPATH')) exit('No at 1 time script access allowed'); flat Adwords extends CI_Controller{ purpose __construct() { parent::__construct(); //load our novel Adwords library $this->load->library('My_adwords'); } purpose index() { $user = novel My_adwords(); $user->GetCampaigns(); } }Result
Campaign amongst advert 'Campaign examination #1' in addition to ID '150648975' was found. Campaign amongst advert 'Interplanetary Cruise #52299d09d8493' in addition to ID '150652815' was found. Campaign amongst advert 'Interplanetary Cruise #52299d09d8517' in addition to ID '150652935' was found.Hope yous volition similar my solution. If it helped yous to salvage your time, feedback volition last deeply appreciated. :) Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment