Cant get API to do anything

428 views
Skip to first unread message

TheAinz

unread,
Sep 20, 2017, 10:39:45 AM9/20/17
to AdWords API Forum
Hi,

I've been trying to set the API up on a new server with no success. I've watched the videos, read the help, readme etc. I've downloaded the php client library. I've downloaded the examples. I've got the client ID, secret etc. refresh token all sorted. 

I've set up and rung the API once before a few years ago, and had similar issues, but got it working eventually after a lot of reading around online.

This time, after 3 days, I'm asking for help. There are a lot of people who seem to report similar issues, but the threads are only progressed by sending logs in privately.


When I get to the last stage and run this: php examples/AdWords/v201705/BasicOperations/GetCampaigns.php I get nothing. No errors, no logging of what happened. Just nothing. I'm stumped.

If I edit the GetCampaigns.php file and remove everything but just echo a statement "hello" the file runs and echos "hello".

If I go down the file line by line then un-commenting namespace Google\AdsApi\Examples\AdWords\v201708\BasicOperations;  immediately prevents anything from happening.

Is it related to where the examples are downloaded relative to the client library?

Any ideas on how I can progress this? I'm stumped as I say. Any help appreciated.

Also, I used to run these files in a browser by removing the section in each example file that prevented this. Is there a similar workaround in the latest release? 

Thanks,

Neil

Shwetha Vastrad (AdWords API Team)

unread,
Sep 20, 2017, 2:17:09 PM9/20/17
to AdWords API Forum
Hi Neil, 

All our examples are meant to be run via the command line and not as a webpage. Could you check if the clientCustomerId in the configuration file is that of an AdWords manager account? Since campaigns are associated with AdWords accounts, not manager accounts, you'll not be able to get any campaigns if you target the manager account. If your account has only Video Campaigns, you'll not be able to use CampaignService to retrieve them because Video Campaigns are not supported in AdWords API services at the moment. They are only supported in AdWords API reports. You can enable logging by following the instructions provided here. If you encounter any error, let me know and I can help you out. 

Regards,
Shwetha, AdWords API Team.

TheAinz

unread,
Sep 21, 2017, 5:21:48 AM9/21/17
to AdWords API Forum
Thanks Shwetha,

I know you have set them up for command line use. This is what I am doing now but still the result is nothing. So I have 2 queries: 

1) You used to be able to run in a browser by commenting out the following code - Is it still possible? Where do I find the code in the new files pls?

// Don’t run the example if the file is being included.
if (__FILE__ != realpath($_SERVER[‘PHP_SELF’])) {
return;

2) The main problem is that when running from the command line nothing happens. I've had logging enabled:

[LOGGING]
; Optional logging settings.
 soapLogFilePath = "/home/performa/public_html/soap.log"
 soapLogLevel = "INFO"
 reportDownloaderLogFilePath = "/home/performa/public_html/report-downloader.log"
 reportDownloaderLogLevel = "INFO"
 batchJobsUtilLogFilePath = "/home/performa/public_html/bjutil.log"
 batchJobsUtilLogLevel = "INFO"
 
No logs created tho.

I'm using the client account ID not the MCC account. The campaigns are normal text ads - I've used the API before with no problems, but not since the re-write.

So the position is, I run the GetCampaigns.php file from the command line. Nothing happens, just back to the $ prompt. No other info. No soap.log content to refer to. No indication at all of why it won't work.

I am wondering  per my initial post if the location of the example files relative to the library and the new namespace definitions is causing it to fail. If I comment out the namespace line I can get the GetCampaigns.php file to echo "hello". If  I uncomment nothing happens. I can't help wondering why composer.phar doesn't download the example files in the right place so testing can be sure to work as part of the package.

Any ideas welcome - I'm stumped with no feedback on why it fails. Thanks.

Shwetha Vastrad (AdWords API Team)

unread,
Sep 21, 2017, 11:27:02 AM9/21/17
to AdWords API Forum
Hi,

Could you try out the suggestions in this post to run the examples in a browser? Could you also try out the examples without any modification from the command line and let me know if logs are generated? Since you have set the log level to INFO, for successful API requests, only a one-line summary is logged. Could you change the logging level to DEBUG and send over any log files generated when you run the GetCampaigns.php example? I would also suggest that you create a post on the library's issue tracker so the library owners can help you out. 

TheAinz

unread,
Sep 21, 2017, 1:38:55 PM9/21/17
to AdWords API Forum
Hi Shwetha,

The browser post refers to what I used previously with the old library (pre 25.0.0). The query is about whether same can be done with the new library? I can't locate in the code where the browser is prevented at the moment.

I've been running the GetCampaigns.php file from the command line previously without modifications and get nothing. I've now changed the logging level to DEBUG and tried again as you suggest. Same issue. Nothing happens, no feedback. Still stumped :-)

I'll post on the library issue tracker as you suggest. 

Thanks for your help.

Neil

TheAinz

unread,
Sep 28, 2017, 11:19:00 AM9/28/17
to AdWords API Forum
Hi again,

Knack has helped me get the library working on my local machine. I now get error messages. I now have this error, despite seemingly following the OAuth instructions and get the refresh token etc.

"# php GetCampaigns.php
PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response:
{
 "error": "unauthorized_client",
 "error_description": "Unauthorized"
}

 in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace:
#0 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 C:\xampp\htdocs\performance-leads\adwords-exampl in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response:
{
 "error": "unauthorized_client",
 "error_description": "Unauthorized"
}

 in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace:
#0 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 C:\xampp\htdocs\performance-leads\adwords-exampl in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113

ainzclan@DESKTOP-4D4ICSK c:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\examples\AdWords\v201708\BasicOperations"

Any ideas what I am doing wrong? Thanks, Neil

Shwetha Vastrad (AdWords API Team)

unread,
Sep 28, 2017, 1:13:33 PM9/28/17
to AdWords API Forum
Hi,

The unauthorized_client error usually occurs when you are using incorrect OAuth2 credentials. Could you check if you have provided the correct clientId, clientSecret and refreshToken? Could you try generating a new refresh token by following the instructions provided hereCould you also try the CURL request provided below and see if you are able to generate the access tokens? That will help you confirm if your OAuth2 credentials are valid or not.

    -d refresh_token=MCC_refresh_token  \
    -d client_id=your-client-id  \
    -d client_secret=your-client-secret  \
    -d grant_type=refresh_token

TheAinz

unread,
Sep 28, 2017, 5:06:00 PM9/28/17
to AdWords API Forum
Hi Swetha,

I've been through that again and recreated credentials. Running GetCampaigns.php now allows login but creates the following errors:

"# php GetCampaigns.php
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl' : failed to load external entity "https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl"
 in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php on line 68
PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl' : failed to load external entity "https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl"
 in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php:68
Stack trace:
#0 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php(68): SoapClient->SoapClient('https://adwords...', Array)
#1 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\AdWords\v201708\cm\CampaignService.php(146): Google\AdsApi\Common\AdsSoapClient->__construct('https://adwords...', Array)
#2 [internal function]: Google\AdsApi\AdWords\v201708\cm\CampaignService->__construct(Array)
#3 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\goog in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php on line 68

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl' : failed to load external entity "https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl"
 in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php:68
Stack trace:
#0 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php(68): SoapClient->SoapClient('https://adwords...', Array)
#1 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\AdWords\v201708\cm\CampaignService.php(146): Google\AdsApi\Common\AdsSoapClient->__construct('https://adwords...', Array)
#2 [internal function]: Google\AdsApi\AdWords\v201708\cm\CampaignService->__construct(Array)
#3 C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\goog in C:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\vendor\googleads\googleads-php-lib\src\Google\AdsApi\Common\AdsSoapClient.php on line 68

ainzclan@DESKTOP-4D4ICSK c:\xampp\htdocs\performance-leads\adwords-examples-30.0.0\examples\AdWords\v201708\BasicOperations"

Having read some similar posts I have tried to access https://adwords.google.com/api/adwords/cm/v201708/CampaignService?wsdl using Curl and it works fine.

Does this mean there is a SOAP set up issue on my machine? Any ideas how to identify and progress? 

Current PHP version: 7.1.9

Thanks Neil

Shwetha Vastrad (AdWords API Team)

unread,
Sep 29, 2017, 10:25:27 AM9/29/17
to AdWords API Forum
Hi, 

Could you try and see if the suggestions mentioned here resolves your issue? If it doesn't, please create a new issue on the PHP client library and share these details there. The PHP library owners are better equipped to assist you. 
Reply all
Reply to author
Forward
0 new messages