Trying Google Adwords API ver v201609 - Got some error

409 views
Skip to first unread message

Pradeep Kumar

unread,
Sep 5, 2017, 1:52:23 AM9/5/17
to AdWords API Forum
Hi All,
I am using google adwords php api and i got stuck while accessing the GetReportFields.php file.

When i execute this file then an error log file generated which says.

[04-Sep-2017 12:05:50 UTC] PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'Config file not found as specified: 'adsapi_php.ini'. Home directory could not be located so it was not searched.' in /home/techximu/public_html/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/ConfigurationLoader.php:71
Stack trace:
#0 /home/techximu/public_html/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/OAuth2TokenBuilder.php(61): Google\AdsApi\Common\ConfigurationLoader->fromFile('adsapi_php.ini')
#1 /home/techximu/public_html/adwords/examples/AdWords/v201609/Reporting/GetReportFields.php(63): Google\AdsApi\Common\OAuth2TokenBuilder->fromFile()
#2 /home/techximu/public_html/adwords/examples/AdWords/v201609/Reporting/GetReportFields.php(76): Google\AdsApi\Examples\AdWords\v201609\Reporting\GetReportFields::main()
#3 {main}
  thrown in /home/techximu/public_html/adwords/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Common/ConfigurationLoader.php on line 71


Can someone help me to fix this issue.

Thank you........ 

Vincent Racaza (AdWords API Team)

unread,
Sep 5, 2017, 2:38:19 AM9/5/17
to AdWords API Forum
Hi Pradeep,

The error means that it could not locate the adsapi_php.ini in your home directory. Please make sure that the configuration file is in the home directory. Or, if it is not in your home directory, then kindly set the correct location in fromFile() method as described here:

$oAuth2Credential = (new OAuth2TokenBuilder())
       
->fromFile('location/to/your/adsapi_php.ini')
       
->build();

// Construct an API session configured from a properties file and the OAuth2
// credentials above.
$session
= (new AdWordsSessionBuilder())
       
->fromFile('location/to/your/adsapi_php.ini')
       
->withOAuth2Credential($oAuth2Credential)
       
->build();

Let me know if this helps.

Thanks,
Vincent
AdWords API Team

Pradeep Kumar

unread,
Sep 5, 2017, 10:29:34 AM9/5/17
to AdWords API Forum
Hi Vincent,

I tried to o the same but getting same error.
What i did is given below. Please have a look and guide me what am i doing wrong??



  public function fromFile($path = null) {
    /*if ($path === null) {
      
      $path = self::DEFAULT_CONFIGURATION_FILENAME;
      
    }*/
    
    $path = '/home/techximu/public_html/adwords/examples/AdWords/adsapi_php.ini';
    
    return $this->from($this->configurationLoader->fromFile($path));
  }


Also i am attaching the file please advise .

OAuth2TokenBuilder.php

Pradeep Kumar

unread,
Sep 5, 2017, 10:41:45 AM9/5/17
to AdWords API Forum

Also I am running Api from http://*****.com/adwords/examples/AdWords/v201609/Reporting/GetReportFields.php

and i configured the file as you mentioned.

public static function main() {
    // Generate a refreshable OAuth2 credential for authentication.
    $oAuth2Credential = (new OAuth2TokenBuilder())
        ->fromFile('/public_html/adwords/examples/AdWords/v201609/adsapi_php.ini')
        ->build();

    // Construct an API session configured from a properties file and the OAuth2
    // credentials above.
    $session = (new AdWordsSessionBuilder())
        ->fromFile('/public_html/adwords/examples/AdWords/v201609/adsapi_php.ini')
        ->withOAuth2Credential($oAuth2Credential)
        ->build();
    self::runExample(new AdWordsServices(), $session);
  }

Please guide

Vincent Racaza (AdWords API Team)

unread,
Sep 5, 2017, 11:29:38 PM9/5/17
to AdWords API Forum
Hi Pradeep,

It seems that you are running the PHP examples from a web application. Our PHP examples are meant to be run in a command prompt, and not in a web page as stated here.

Also, you don't need to update the OAuth2TokenBuilder.php. What you need to update is just the fromFile() method of the GetReportFields.php itself. Aside from that, kindly make sure that you installed the client library using Composer as noted here.

Please try to run this first in the command prompt and let us know if you encounter any issues.

Pradeep Kumar

unread,
Sep 6, 2017, 5:32:52 AM9/6/17
to AdWords API Forum
Hi Vincent,

Thank you for your kind support. I did the same and run it on CMD the previous errors are resolved now i am getting a new error which is given velow.


[06-Sep-2017 08:11:54 UTC] PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response:
{
 "error": "invalid_client",
 "error_description": "Unauthorized"
}

'
in /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::Guzzle in /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
[06-Sep-2017 08:29:15 UTC] PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `401 Unauthorized` response:
{
 "error": "invalid_client",
 "error_description": "Unauthorized"
}

'
in /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/techximu/public_html/adwords/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::Guzzle in /home/techximu/public_html/adwords/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113


Vincent Racaza (AdWords API Team)

unread,
Sep 6, 2017, 6:20:37 AM9/6/17
to AdWords API Forum
Hi Pradeep,

Could you confirm if you generated your client ID and secret using "Installed app" type? Please ensure that you followed the guide here in authenticating using installed app type. Also, could you confirm if the email address associated to the clientId has access on the client account that you are targeting?

If you can confirm these, and still the issue persists, then kindly provide your clientCustomerId as well as the email address associated to it. Please use the Reply privately to author option when replying.

Pradeep Kumar

unread,
Sep 6, 2017, 9:08:29 AM9/6/17
to AdWords API Forum
Dear while accessing the script then i am getting an error which is attached please have a look on the attachment.
Pasted image at 2017_09_06 06_37 PM.png

Pradeep Kumar

unread,
Sep 7, 2017, 1:20:13 AM9/7/17
to AdWords API Forum
Dear Vincent,

Thank you for for kind help. You are very helpful and your info takes me to the right path.

I read all your previous information and again i did the same thing you you know what now the API is working fine/

Once again thank you for for help.

Pradeep Kumar

unread,
Sep 8, 2017, 12:49:00 AM9/8/17
to AdWords API Forum
Dear Vincent,

I hope you are doing well.

I want more help from you regarding the API.

I am trying to display text ads of a particular group but unable to fetch that ads.

also i am trying to fetch Impressions, Clicks, creatives from the campaigns but unable to fetch that data.

Please guide me how to do this task through api.

Pradeep Kumar

unread,
Sep 8, 2017, 2:40:08 AM9/8/17
to AdWords API Forum
While Accessing  new fields like budget, clicks, impressions then i am getting an error.

Please help to get these data from google adwords api

kanhaiya....@gmail.com

unread,
Sep 8, 2017, 3:18:38 AM9/8/17
to AdWords API Forum

Hi Vincent,
Thank you so much for helping me throughout the integration process.

my name is Kanhaiya, a colleague of Pradeep working on the same API integration.

We have done the integration. Now we have some issue related to fetching the data like clicks, imprssion, creatives, conversion etc. Let me tell you we are able to access campaign name, adgroups, campaign status, campaign ID only.

now when i try to fetch click, impr. ad copy (display, search) etc. we are getting zero result found. Can you please help me here?

Thank You.

Vincent Racaza (AdWords API Team)

unread,
Sep 8, 2017, 3:37:36 AM9/8/17
to AdWords API Forum
Hi,

I assume that both you and Pradeep have the same issue right now on which you could not get the metrics (clicks, impressions, etc.) result in the AdWords API.

These metrics can only be retrieved using reports. For example, for campaigns, you can get the performance data using Campaign Performance Report. You can check this guide for more information on reporting in the AdWords API. For the PHP reporting examples, kindly check here.

Also, if you have further clarifications, kindly create a new forum thread so we can track your new concern/issue better.
Reply all
Reply to author
Forward
0 new messages