Yahoo! Search Marketing

Sample Code: PHP Client Application

To access Enterprise Web Services (EWS) using the sample PHP client application, follow these instructions.

Environment

To set up your PHP environment, perform these tasks:

1. Install PHP 5.1.2 or higher.

2. Install PHP mbstring module.

3. Enable the PHP soap extension.

  • Windows: add "extension=<ext-dir>/php_soap.dll" to php.ini
  • Unix: add "extension=<ext-dir>/soap.so" to php.ini

4. Enable the PHP SSL extension.

  • Windows: add "extension=extension=<ext-dir>/php_openssl.dll" to php.ini
  • Unix: use php with ssl compiled in.

Note: Contact your system administrator if you need help setting up your PHP environment.

Source Code and Sample Data

For PHP, the source code and sample data includes:

Build and Run

To build and run the PHP client application:

1. Download YahooEWSClient.php and sample data properties files (sample_data_*.properties), and save them to your local directory.

2. Edit YahooEWSClient.php to contain your EWS credentials, which are defined near the top of the file:

  • username
  • password
  • masterAccountID
  • accountID
  • license
  • MARKET

3. Run the application using this command:

prompt> php -f YahooEWSClient.php

Known Issues

The Marketing API represents the following ID elements as 64 bit long values:

  • The paymentMethodID used in AccountService and UserManagementService.
  • The IDs for the Ad, AdGroup, Campaign, ExcludedWord, and Keyword data objects.

The PHP language does not support the 64 bit long data type. The maximum integer value in PHP is 2147483647. This limitation can cause PHP applications to generate bad requests if the ID element is larger than 2147483647.

Please consider the following rules when writing PHP applications for EWS API.

1. When the ID is represented as a string variable, cast it to float to ensure that values larger than 2147483647 are handled correctly. For example:

	

$wsdl="https://sandbox.marketing.ews.yahooapis.com/services/V4/CampaignService?wsdl"

$client = new SoapClient($wsdl, ...)

$ID = "9999999999999"; // BAD. Generates request with <campaignID>2147483647</campaignID>

$ID = (float) "9999999999999"; // Safe.

$params = array('campaignID' => $ID);

$client->__SoapCall('getCampaign', array($params));

;

2. When the ID is represented as a numeric variable, the PHP runtime automatically casts large values to float. Hence, the following is safe:

  

$wsdl="https://sandbox.marketing.ews.yahooapis.com/services/V4/CampaignService?wsdl"

$client = new SoapClient($wsdl, ...)

$ID = 9999999999999; // Safe

$params = array('campaignID' => $ID);

$client->__SoapCall('getCampaign', array($params));