While it is an ongoing project, the PHP library for AdWords does not yet fully make use of proper namespacing througout. Until that is complete, it may be advisable to use a "psedudo namespaced" version that simply prepends a bit of data to class names. Note that if you do it this way, you will want to use this format for creating objects. It's also a better practice anyway.
// Old
$tracker = new AdWordsConversionTracker();
// New
$conversionTrackerService = $this->adwords_user->GetService('ConversionTrackerService');
$tracker = $conversionTrackerService->Create('AdWordsConversionTracker');
I'm making the assumption that you are already using this library in production and trying to migrate it before the sunset deadline.
- Clone the current repository, e.g.
cd /some/project/directory ; git clone git@github.com:googleads/googleads-php-lib.git
. - Install
phing
as described here. This is used to do the build task.
Next, you will need to patch the current WDSL with a previous tagged version (that uses pseudo namespacing instead of the partial namespacing support.) These instructions via @saturnism on the related issue.
$ cd /path/to/downloaded-repository
# make a new branch for pseudo-namespace
$ git checkout 5.3.0
$ git checkout -b 5.3.0-pns
# replace build_lib w/ older version
$ cd build_lib
$ rm -rf *
$ git checkout 5.2.3 .
With that now patched, you have a few more edits to make in the build process. Within the <project>
tag, around line 7, add this line in order to properly tell phing
where to build from.
<project basedir="../" default="generate-src" name="adsapi_php">
<property file="src/Google/Api/Ads/AdWords/Lib/api.properties" />
<property file="src/Google/Api/Ads/Dfp/Lib/api.properties" />
<property name="classpath" value="" />
[...]
Next, you will want to tell phing
to use the psedo namespaces. Edit src/Google/Api/Ads/AdWords/Lib/api.properties
to add:
;; Patched to use 5.2.3 declaration
wsdl2php.enablePseudoNamespaces=True
With these in place, you should now be able to run the builder.
$ cd build_dir
$ phing
This will kick off the generation process that will take a minute or so.
There will be a few issues with using the project as-is because of some improper class naming in the build script. The first error will say that it is unable to find the Google_Api_Ads_AdWords_Lib_AdWordsSoapClient
class.
Do a mass find/replace for the following in your project folder:
extends Google_Api_Ads_AdWords_Lib_AdWordsSoapClient
to
extends AdWordsSoapClient
The next time it will complain about not be able to find the native classes (as they are called through GetService
). You will need to patch Google/Api/Ads/Common/Lib/SoapClientFactory.php
(also via @saturnism).
public function GenerateSoapClient($serviceName) {
...
$this->DoRequireOnce($serviceName);
// Add the following line, assuming you only use the AdWords components
$serviceName = 'Google_Api_Ads_AdWords_' . $this->GetVersion() . '_' . $serviceName;
$soapClient = ...
...
}
At this point, your library is patched to use the new v201402
version. Copy the relevant files into your project and start working through the other changes outlined in the migration guide.
This fork of the code has followed the instructions if you just want to quickly get going:
https://github.com/stephenyeargin/googleads-php-lib/tree/5.3.0-pns