Using the AdWords API Sandbox

in AdWords API

Please note that the AdWords API Sandbox has been deprecated, and you should now test your applications using a test account.

The sandbox environment for the AdWords API enables you to test out your applications without worrying about using up quota units or making inadvertent errors which damage live campaigns. This article shows you how to access it using the PHP client library.

Connecting To the AdWords API Sandbox

You don't need to sign up for the API in order to run your code in the sandbox environment, you can just use any Google account to login and test your software. However, there are a few additional steps that you need to follow:

  • Generate a sandbox developer token.
  • Change the URL where you send your API requests.
  • Create a sandbox MCC account.
  • Obtain a list of dummy accounts to use.

The following sections describe these steps in detail.

The Sandbox Developer Token

Although you don't need to sign up for the production API and get an official token, you do need to supply something in the header, which is simply the username that you're using to login postfixed with the string ++[currency_code]. The currency code just needs to be any valid one, so if you have a Google account called [email protected] and want to use USD for the currency, then the developer token would simply be [email protected]++USD.

This then gives us the first few lines of PHP for a script that uses the sandbox:

<?php
 
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
 
$username = "[email protected]";
$password = "pa55word";
$currencyCode = "USD";
$developerToken = "$username++$currencyCode";
AdWords API Sandbox Credentials

The Sandbox URL

To use the sandbox servers instead of live servers, you simply need to change the default URL from https://adwords.google.com/ to https://adwords-sandbox.google.com/. This can be done with the SetDefaultServer() method of the AdWordsUser object. This gives us our next few lines of code:

$user = new AdWordsUser(null, $username, $password, $developerToken);
$user->SetDefaultServer("https://adwords-sandbox.google.com/"); 
$user->SetClientId(null);
Setting the Sandbox URL

Creating Sandbox Accounts

The Google account that you use to login to the sandbox is always considered an MCC account; you therefore need some advertiser accounts with which to work. These are auto-generated the first time you make a call to the CampaignService. This call doesn't even need to succeed so you can simply create your accounts using the following code:

try {
    $campaignService = $user->GetService("CampaignService", 'v201209');
    $page = $campaignService->get(new Selector());
} catch (Exception $e) {}
Initializing Sandbox Advertiser Accounts

Listing Sandbox Accounts

Finally, you need to get the customerId of an account to use in the sandbox. The call to the CampaignService created five dummy accounts, and you can list them using a get call to the ManagedCustomerService:

$managedCustomerService = $user->GetService('ManagedCustomerService', 'v201209');
$selector = new Selector();
$selector->fields = array('Login', 'CustomerId', 'Name');
$page = $managedCustomerService->get($selector);
 
$accounts = array();
foreach ($page->entries as $account) {
    if ($account->customerId > 0) {
        $accounts[] = $account;
    }
}
 
foreach ($accounts as $account) {
    print "Customer ID: {$account->customerId}\n";
}
Listing Sandbox Advertiser Accounts

We can now use one of the accounts to make API calls:

$customerId = $accounts[0]->customerId;
$user->SetClientId($customerId);
 
$budgetService = $user->GetService('BudgetService', 'v201209');
 
$budget = new Budget();
$budget->name = 'Test Budget #' . time();
$budget->period = 'DAILY';
$budget->amount = new Money((float) 10000000);
$budget->deliveryMethod = 'STANDARD';
 
$operations = array();
 
$operation = new BudgetOperation();
$operation->operand = $budget;
$operation->operator = 'ADD';
$operations[] = $operation;
 
$result = $budgetService->mutate($operations);
$budget = $result->value[0];
 
$campaignService = $user->GetService("CampaignService", 'v201209');
 
$campaign = new Campaign();
$campaign->name = "Test Sandbox Account #" + time();
$campaign->status = "ACTIVE";
$campaign->biddingStrategy = new ManualCPC();
 
$campaign->budget = new Budget();
$campaign->budget->budgetId = $budget->budgetId;
 
$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = TRUE;
$campaign->networkSetting = $networkSetting;
 
$campaign->settings = array(new KeywordMatchSetting(false));
 
$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'ADD';
 
$operations = array($operation);
$result = $campaignService->mutate($operations);
 
print_r($result);
Listing Sandbox Create Campaign

Full Example Code

Here's the full code from this tutorial:

<?php
 
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
 
$username = "[email protected]";
$password = "pa55word";
$currencyCode = "USD";
$developerToken = "$username++$currencyCode";
 
$user = new AdWordsUser(null, $username, $password, $developerToken);
$user->SetDefaultServer("https://adwords-sandbox.google.com/");
$user->LogAll();
$user->SetClientId(null);
 
try {
    $campaignService = $user->GetService("CampaignService", 'v201209');
    $page = $campaignService->get(new Selector());
} catch (Exception $e) {
 
}
 
$managedCustomerService = $user->GetService('ManagedCustomerService', 'v201209');
$selector = new Selector();
$selector->fields = array('Login', 'CustomerId', 'Name');
$page = $managedCustomerService->get($selector);
 
$accounts = array();
foreach ($page->entries as $account) {
    if ($account->customerId > 0) {
        $accounts[] = $account;
    }
}
 
foreach ($accounts as $account) {
    print "Customer ID: {$account->customerId}\n";
}
 
$customerId = $accounts[0]->customerId;
$user->SetClientId($customerId);
 
$budgetService = $user->GetService('BudgetService', 'v201209');
 
$budget = new Budget();
$budget->name = 'Test Budget #' . time();
$budget->period = 'DAILY';
$budget->amount = new Money((float) 10000000);
$budget->deliveryMethod = 'STANDARD';
 
$operations = array();
 
$operation = new BudgetOperation();
$operation->operand = $budget;
$operation->operator = 'ADD';
$operations[] = $operation;
 
$result = $budgetService->mutate($operations);
$budget = $result->value[0];
 
$campaignService = $user->GetService("CampaignService", 'v201209');
 
$campaign = new Campaign();
$campaign->name = "Test Sandbox Account #" + time();
$campaign->status = "ACTIVE";
$campaign->biddingStrategy = new ManualCPC();
 
$campaign->budget = new Budget();
$campaign->budget->budgetId = $budget->budgetId;
 
$networkSetting = new NetworkSetting();
$networkSetting->targetGoogleSearch = TRUE;
$campaign->networkSetting = $networkSetting;
 
$campaign->settings = array(new KeywordMatchSetting(false));
 
$operation = new CampaignOperation();
$operation->operand = $campaign;
$operation->operator = 'ADD';
 
$operations = array($operation);
$result = $campaignService->mutate($operations);
 
print_r($result);
?>
AdWords API Sandbox Script

← WordPress Plugins Phoning Home AdWords Page Event Conversion Tracking →

To help me decide what to write about, I'd like to asses the value of my blog posts to see which ones people find most beneficial. If you found the information here useful then could you please +1 it, but if you didn't find what you were looking for then please leave a comment and I'll be happy to help where I can. Thanks!

Comments

I'm keen to get feedback on my posts, so if you have any questions or comments, then please send me a message and I'll be happy to help.

Hassan

Hi Ewan, i need your help :(

i want get campaigns , whene i use the sandbox serveur i get this error :

Warning: SoapClient::SoapClient(https://adwords-sandbox.google.com/api/adwords/cm/v201206/CampaignService?wsdl) [soapclient.soapclient]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable in D:\www\adwords\test.php on line 80

Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com/api/adwords/cm/v201206/CampaignService?wsdl' : failed to load external entity "https://adwords-sandbox.google.com/api/adwords/cm/v201206/CampaignService?wsdl" in D:\www\adwords\test.php on line 80

if i change the ADWORDS_API_SERVER to https://adwords.google.com no error , but no result . tnx

Reply

Ewan

Hi Hassan,

The sandbox doesn't exist anymore, you need to create a test account.

Also, I noticed that you're using v201206 of the API, which will be deprecated soon, you should be using v201209 at the moment.

Regards,

Ewan

Reply

hassan

Hi ewan ,

I already have my account adwords active with my token developer , is that my campaigns is only displayed with a sandbox account ?

how I can make the difference between a test account and my account adwords

I try get this compaigns with https://adwords.google.com/api/adwords/

"All requests to the Test Accounts should be sent to the same endpoint as the production requests"

but i get this

object(CampaignPage)[199] public 'totalBudget' => object(Budget)[202] public 'period' => string 'DAILY' (length=5) public 'amount' => object(Money)[198] public 'microAmount' => int 0 public 'ComparableValueType' => string 'Money' (length=5) private '_parameterMap' (ComparableValue) => array ... public 'deliveryMethod' => null public 'entries' => null public 'totalNumEntries' => int 0 public 'PageType' => string 'CampaignPage' (length=12) private '_parameterMap' (Page) => array 'Page.Type' => string 'PageType' (length=8).

entries its empty

Tnx ewan for your help Hassan Absike

Reply

Hi,

is this tutorial still valid? The documentation on using the AdWords TestAccount seems to say that we should use the same API endpoint as with "normal" requests - and when I try to access anything on adwords-sandbox.google.com I get various forms of 502 and 503 errors (even when I just try to access the WSDL). Not sure because there may be a difference between "Sandbox" and "Test Account"...

On the other hand working with the normal server URL I also get errors - just other ones...

Regards, Dominik

Reply

... okay, "Sandbox" documentation forwards to "Test Account", so we're talking about the same thing... I think...

Reply

... and if anybody else is wondering: Sandbox is dead - Test-Accounts are are the new way to do this.

Reply

Hi,

I have used your code and it shows me some output. But where I can see if I have created any ads or ad groups?

Any idea where I can log in and see i my code is worked as I need ?

Thanks Jayesh

Reply

Ewan

Hi Jayesh,

There isn't any user interface for the sandbox, but Google has developed a sample Java application that can be used to view the contents of a sandbox account. You can download it from the Java Client Library project page.

Regards,

Ewan

Reply

Hey Ewan,

You are rocking :). this is what exactly I was looking for.

I am moving ahead in world of Google Adwards API. I may ask you if I have any Qs.

I am simply impressed with your quick answer.

Thank you very much

Reply

laid

hello,

i'm new in adwords API, please can you explaine to me step by step how to run this script from the beginning.( from downloading the php librery...).

Thank you so much.

Reply

krunal

Thank you very much, finally I got some output. This takes out my frustration.

Reply

derjanni

Nice article! I've written one in German as well: Adwords API. Maybe Germans are interested in it as well ;-)

Reply

Dani

I downloaded and setup the PHP SDK, including the sample app. I was able to get OAuth2 working using anonymous credentials against the Sandbox, however when I login with my Google account, it finds 0 campaigns, and 1 account (customerId 0), with no new accounts generated, or ability to create new campaigns.

I tried the sample web app, logged in, but still no new accounts generated. What could I be doing wrong? I've tried logging in using my personal gmail address and a google apps user account from my business.

Thanks, Dani

Reply

Ewan

Hi Dani,

The first time you login to the sandbox, you need to use a username and password instead of oAuth; otherwise the test accounts won't be created: http://adwordsapi.blogspot.co.uk/2011/10/adwords-api-now-fully-supports-oauth.html

Regards,

Ewan

Reply

Allan

I am also having a similar issue. All the five accounts that were generated has a customerId of 0. And when I try to add some campaigns, I am getting this error: OperationAccessDenied.ADD_OPERATION_NOT_PERMITTED @ operations[0]

Reply

Ewan

Hi Allan,

There's a current problem with the AdWords API sandbox that's causing this; Google's working on the problem, but doesn't usually provide ETA's to external developers. I assume that it will be fixed soon as it's an issue that's affecting many people.

Regards,

Ewan

Reply

sang

Help full example? $result show:

CampaignReturnValue Object ( [value] => Array ( [0] => Campaign Object ( [id] => 784555 [name] => 1349753874 [status] => ACTIVE [servingStatus] => SERVING [startDate] => 20121008 [endDate] => 20371230 [budget] => Budget Object ( [period] => DAILY [amount] => Money Object ( [microAmount] => 10000000 [ComparableValueType] => Money [_parameterMap:ComparableValue:private] => Array ( [ComparableValue.Type] => ComparableValueType ) ) [deliveryMethod] => STANDARD ) [biddingStrategy] => ManualCPC Object ( [enhancedCpcEnabled] => [BiddingStrategyType] => ManualCPC [_parameterMap:BiddingStrategy:private] => Array ( [BiddingStrategy.Type] => BiddingStrategyType ) ) [conversionOptimizerEligibility] => ConversionOptimizerEligibility Object ( [eligible] => 1 [rejectionReasons] => ) [campaignStats] => [adServingOptimizationStatus] => OPTIMIZE [frequencyCap] => FrequencyCap Object ( [impressions] => 0 [timeUnit] => [level] => ) [settings] => Array ( [0] => GeoTargetTypeSetting Object ( [positiveGeoTargetType] => DONT_CARE [negativeGeoTargetType] => DONT_CARE [SettingType] => GeoTargetTypeSetting [_parameterMap:Setting:private] => Array ( [Setting.Type] => SettingType ) ) ) [networkSetting] => NetworkSetting Object ( [targetGoogleSearch] => 1 [targetSearchNetwork] => 1 [targetContentNetwork] => 1 [targetContentContextual] => 1 [targetPartnerSearchNetwork] => ) ) ) [ListReturnValueType] => CampaignReturnValue [_parameterMap:ListReturnValue:private] => Array ( [ListReturnValue.Type] => ListReturnValueType ) )

thank you!

Reply

Arman

Hi Ewan

Using this code i get the following error: Fatal error: Uncaught SoapFault exception: [soap:Client] Unmarshalling Error: For input string: "" in C:\xampp\htdocs\test\testcake\app\controllers\components\aw_api_php_lib_3.0.1\src\Google\Api\Ads\Common\Lib\AdsSoapClient.php:201 Any idea why I get this error ?? Thank you for advice and for this tutorial :)

Reply

Ewan

Hi Arman,

I've tried out the code with the 3.0.1 PHP client library, but didn't get any errors; are you using the exact code from above, and just changing the username and password fields to a valid Google account?

Regards,

Ewan

Reply

The code works (apparently). Why should i say apparently? Because I changed this part

try { $campaignService = $user->GetService("CampaignService", 'v201109'); $page = $campaignService->get(new Selector()); } catch (Exception $e) {}

to

try { $campaignService = $user->GetService("CampaignService", 'v201109'); $page = $campaignService->get(new Selector()); } catch (Exception $e) { echo $e->getMessage(); }

And I'm the getting the following error

[SelectorError.MISSING_FIELDS @ serviceSelector]

Any hints? What does that means?

Thanks!

Reply

Ewan

Hi Ricardo,

That exception is deliberately ignored because the call to the campaign service isn't actually meant to succeed: The procedure to initialise the sandbox with a set of client accounts involves making a call to an AdWords API service using a Google account and a dummy developer token; however, to make a call to the campaign service, you need to supply the customer id of a client account--which isn't possible as you haven't generated one yet--so you need to catch and ignore the exception informing you that you haven't supplied a customer id. Does that make sense?

This error means that you haven't requested the minimum required campaign fields to query the campaign service, but I haven't bothered to specify any because if I did I would just get a missing customer id error instead.

Regards,

Ewan

Reply

Aye

Hi Ewan,

Thanks for tutorial.

using this code how to add or search keywords in google adwords api

Advance thanks, Aye

Reply

R K RAJAN

Hi Ewan,

Very useful tutorial

Here I need few extra thing in this code. How to add keywords for this campaign. can you help me..

Reply

Robert

Hi. I am getting the exact same problem as Hector on March 6th. However, I tired with 3 different gmail accounts and I am getting

Customer ID: 0 Customer ID: 0 Customer ID: 0 Customer ID: 0 Customer ID: 0

on each one.

Reply

Ewan

Hi Robert,

Are you getting any error message?

Thanks,

Ewan

Reply

Sander

I have the exact same problem, were you able to fix this ?

Reply

Ewan

Hi Sander,

There was an error with the sandbox a while ago that was causing this, but I thought it had been resolved: https://groups.google.com/forum/?fromgroups#!topic/adwords-api/pt6JBHCgxNE - maybe you should try it with a different Google Account?

Reply

Bill

Very nice tutorial Ewan - much appreciated!!

Bill

Reply

Ewan

Glad to hear it was useful Bill! What other tutorials might you find interesting?

Reply

kia

Hi Ewan,

You are my life saver, i've been setting up how to run Adwords API PHP using sandbox, but always fails. Most of the tutorial are Adword API v200909. But when i tried yours, its works perfectly.

Best Regards

Reply

newbie

Warning: require_once(Google/Api/Ads/AdWords/Lib/AdWordsUser.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\x-test\sandbox\ref.php on line 3

Fatal error: require_once() [function.require]: Failed opening required 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\x-test\sandbox\ref.php on line 3

iam having this error.any idea?

Reply

Akif

Code works perfect thanks! Is it possible to use the Java Sandbox Tool to view te data? I am trying to login and see what is being generated, but it doesn't work. (or I don't know how to do it)

Reply

Ewan

Yes, you should be able to use the Java Sandbox Tool; what problem are you getting?

Reply

Akif

Thanks for your super fast reply. I just don't know which credentials I have to use, i guess. When i use only the email address and the password of the MCC account after I run the above code it logs in ok. But when i try to see the campagins it says (404) not found.

Reply

Ewan

Yes, I think there's actually a general problem with the viewer at the moment due to the recent deprecation of the old API versions. The AdWords API team hasn't updated it yet. There's more on the forum at: https://groups.google.com/forum/?fromgroups#!topic/adwords-api/7hJDc8VkHnc

Reply

Akif

I runned above code with succes. Then when i try to see those changes in the sanbox viewer i get a 404 error. I don't know if I use the right credentials. I'm using the email and password inserted in the code, is this right?

Reply

Ewan

Google's not actually upgraded it yet since they switched off all the old versions of the API! So it won't be usable until they do fix it. I'm having a look at it myself at the moment to see if I can get it working; I've got the basic thing going, but there are some problems with changes Google's made to campaign targeting in the latest version of the API....

Reply

Hector

Pls help me ! THis is my error !!!

Customer ID: 0 Customer ID: 0 Customer ID: 0 Customer ID: 0 Customer ID: 0 Fatal error: Uncaught SoapFault exception: [soap:Server] [AuthorizationError.USER_PERMISSION_DENIED @ ] in C:\AppServ\www\Api Adwords\src\Google\Api\Ads\Common\Lib\AdsSoapClient.php:201 Stack trace: #0 C:\AppServ\www\Api Adwords\src\Google\Api\Ads\Common\Lib\AdsSoapClient.php(201): SoapClient->__soapCall('mutate', Array, NULL, Array, Array) #1 C:\AppServ\www\Api Adwords\src\Google\Api\Ads\AdWords\v201109\CampaignService.php(5728): AdsSoapClient->__soapCall('mutate', Array) #2 C:\AppServ\www\Api Adwords\src\exa.php(57): CampaignService->mutate(Array) #3 {main} thrown in C:\AppServ\www\Api Adwords\src\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 201

TY

Reply

Ewan

Hi Hector,

Sorry for the delay replying; did you get this working in the end?

Regards,

Ewan

Reply

Ewan, thx for response i solved the error i follow this tutorial carefully, and works thx for u time and help

Grettings from Mexico and Thanks

will continue working and researching this API

still posting pls!

Reply

Sander

I have the same error and am a little stumped to the cause. How did you end up fixing this ?

Reply

jozef

i have the same problem :-/

Reply

Sage

I too am getting this error.

Thank you (btw) for doing this awesome tutorial and all your help in the comments. Sage

Reply

Ewan

Hi Sage,

I've checked this out and tried the various methods of listing the accounts, but didn't have any luck as it appears that there's actually an issue with Google's sandbox at the moment where it's not creating new sandbox accounts properly.

I even tried using the latest version of the API (v201206); however, the ServicedAccountService that this tutorial uses has changed to the CustomerService, which also has an issue in the sandbox, so no luck there either!

The AdWords API doesn't usually have so many problems with it, but they must be having some difficulties with the v201206 upgrade because the client libraries have taken longer than usual to be released and they haven't been as active as normal on the forum lately. Anyway, Google usually turns things around pretty quickly, so hopefully this problem will be resolved soon!

Regards,

Ewan

Reply

Dave

Hi, I am getting this error:

Fatal error: Uncaught exception 'AuthTokenException' with message 'Failed to get authToken. Reason: CaptchaRequired' in C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\Common\Util\AuthToken.php:96 Stack trace: #0 C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\AdWords\Lib\AdWordsUser.php(255): AuthToken->GetAuthToken() #1 C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\AdWords\Lib\AdWordsUser.php(267): AdWordsUser->RegenerateAuthToken() #2 C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\AdWords\Lib\AdWordsUser.php(407): AdWordsUser->GetAuthToken() #3 C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\AdWords\Lib\AdWordsUser.php(211): AdWordsUser->ValidateUser() #4 C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\test.php(20): AdWordsUser->GetService('ServicedAccount...', 'v201109') #5 {main} thrown in C:\Program Files\EasyPHP-5.3.8.1\www\aw_api_php_lib_2.7.2\src\Google\Api\Ads\Common\Util\AuthToken.php on line 96

Reply

Ewan

This error message means that you've tried to log into a Google Account too many times using the ClientLogin API. The simple way to fix it is just to go to the normal login screen on the web, access your account, then resolve the CAPTCHA challenge. You should then be able to get the code working.

There is a way to get the CAPTCHA image using code, display it to the user, then send the response back with another attempt to access the API; however, it's better to just use the newer oAuth API and avoid the problem altogether.

Reply

ntboy810

Hi, I am get same error while use 'CreateAccountService' - Sandbox (used OAuth). Please help me. :(.

Forgive me for not speaking English well.

Reply

ntboy810

My error: Fatal error: Uncaught SoapFault exception: [soap:Server] InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ com.google.ads.api.services.common.error.InternalApiError.(InternalApiErro in D:\1.Setup\wamp\www\autodialer\application\libraries\Google\Api\Ads\Common\Lib\AdsSoapClient.php:201 Stack trace: #0 D:\1.Setup\wamp\www\autodialer\application\libraries\Google\Api\Ads\Common\Lib\AdsSoapClient.php(201): SoapClient->__soapCall('mutate', Array, NULL, Array, Array) #1 D:\1.Setup\wamp\www\autodialer\application\libraries\Google\Api\Ads\AdWords\v201109_1\CreateAccountService.php(1803): AdsSoapClient->__soapCall('mutate', Array) #2 D:\1.Setup\wamp\www\autodialer\application\models\model_gapi.php(29): CreateAccountService->mutate(Array) #3 D:\1.Setup\wamp\www\autodialer\application\controllers\gapi.php(155): Model_gapi->CreateAccount(Object(AdWordsUser), 'EUR', 'Europe/London') #4 [internal function]: Gapi->account() #5 D:\1.Setup\wamp\www\autodialer\system\core\CodeIgniter.php(339): call_user_func_array(Array, Array) #6 D:\1 in D:\1.Setup\wamp\www\autodialer\application\libraries\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 201

Reply

Ewan

I don't think it's possible to create accounts in the sandbox, this will only work in the production API.

Reply

Ram krishna dhaker

giving an error Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://adwords-sandbox.google.com//api/adwords/cm/v201109/CampaignService?wsdl" in C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 163

Reply

Ewan

Looks like you've got an issue with your Internet connection. The message just means the PHP SOAP library can't connect to Google and download the WSDL for the CampaignService. Once you have a stable connection then this won't be a problem.

Reply

Ram krishna dhaker

the full error is

Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://adwords-sandbox.google.com/api/adwords/cm/v201109/CampaignService?wsdl" in C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 163

Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "https://adwords-sandbox.google.com/api/adwords/mcm/v201109/ServicedAccountService?wsdl" in C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 163

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords-sandbox.google.com/api/adwords/mcm/v201109/ServicedAccountService?wsdl' in C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php:163 Stack trace: #0 C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php(163): SoapClient->SoapClient('https://adwords...', Array) #1 C:\xampp\php\PEAR\Google\Api\Ads\AdWords\Lib\AdWordsSoapClient.php(53): AdsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ServicedAccount...', 'https://adwords...') #2 C:\xampp\php\PEAR\Google\Api\Ads\AdWords\v201109\ServicedAccountService.php(1858): AdWordsSoapClient->__construct('https://adwords...', Array, Object(AdWordsUser), 'ServicedAccount...', 'https://adwords...') #3 C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\SoapClientFactory.php(146): ServicedAccountService->__construct('https://adwords...', Array, Object(AdWordsUser)) #4 C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\SoapClientFactory.php(82): SoapCl in C:\xampp\php\PEAR\Google\Api\Ads\Common\Lib\AdsSoapClient.php on line 163

IN my local server the soap is installed and it also have the wsdl.php file.then how can i connect to google.

Reply

Ewan

That's strange...is your server able to connect to the Internet? Can you download something using cURL?

Reply

Ram krishna dhaker

the above problem is solved now i am getting new error

Fatal error: Uncaught exception 'Exception' with message 'The header "clientEmail" is not compatible with versions v201109 and later. Use clientCustomerId instead.' in C:\xampp\php\PEAR\Google\Api\Ads\AdWords\Lib\AdWordsSoapClientFactory.php:54 Stack trace: #0 C:\xampp\php\PEAR\Google\Api\Ads\AdWords\Lib\AdWordsUser.php(222): AdWordsSoapClientFactory->__construct(Object(AdWordsUser), 'v201109', 'https://adwords...', NULL, NULL) #1 C:\xampp\htdocs\adword\index.php(19): AdWordsUser->GetService('ServicedAccount...', 'v201109') #2 {main} thrown in C:\xampp\php\PEAR\Google\Api\Ads\AdWords\Lib\AdWordsSoapClientFactory.php on line 54

Reply

Ewan

I think I know the problem, just checking it out....

Reply

Ewan

I'm not actually getting the error. What version of the PHP client library are you using?

Reply

Ram krishna dhaker

aw_api_php_lib_2.7.2

Reply

Ewan

That's the same as I've got, but no error....Anyway, there's not supposed to be a clientEmail or clientCustomerId header sent in the first part of the script. For some reason it is when you try it. Adding the line $user->SetClientId(null); after the user object is initialised should fix it, but I can't test it out without reproducing the error.

I've updated the example, can you run it and see if it works?

Reply

Ram krishna dhaker

what information will we fill in C:\xampp\php\PEAR\Google\Api\Ads\AdWords\auth.ini file.

Reply

Ewan

You shouldn't need to use the auth.ini file, as it's just an alternative to entering the setup parameters directly into the PHP code; you can use it to populate the $user object, but the example above should already set everything that's needed.

Reply

Adam

Mind sharing how you solved the first problem? I'm getting the same error.

Reply

Glenn de Boer

I keep getting a GOOGLE_ACCOUNT_COOKIE_INVALID. Any idea why i get this?

Reply

Ewan

It means that the token generated for the username and password you supplied isn't valid. Are you using the same code as above and just changing the username/password?

Reply

Alex

Works now... And thanks for a great tutorial

Reply

Alex

Doesn't work... makes UNEXPECTED_INTERNAL_API_ERROR at this line:

$page = $accountService->get($selector);

when trying to list sandbox accounts

Reply

Ewan

The UNEXPECTED_INTERNAL_API_ERROR message is quite confusing because it's supposed to mean a problem with the AdWords API servers, but sometimes it can actually be caused by a malformed request; however, in the sandbox the former is more likely, so it's best to retry the request later.

Reply

Darius

I am getting the same error. How long do I need to wait? I am using v201109_1

Reply