googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
294 stars 262 forks source link

Laravel Application not working due to the update of V8 in Google Ads Api #651

Closed SubaKrishnan closed 3 years ago

SubaKrishnan commented 3 years ago

Your client library and Google Ads API versions:

Your environment:

php Version - v7.3.28 Windows - 10 protobuf - v3.18.0 grpc - v1.39.0 Type of Transport - rest

Description of the bug:

I had to upgrade to google-ads-php (https://github.com/googleads/google-ads-php) Version 11 as the google ads api V6 was deprecated and throwing error.

google-ads-php supports google ads api V7. While we tried executing the script I get the following error.

ERROR: Could not construct ApplicationDefaultCredentials {"userId":1,"exception":"[object] (Google\\ApiCore\\ValidationException(code: 0): Could not construct ApplicationDefaultCredentials at D:\\xampp\\htdocs\ eseller-home\\vendor\\google\\gax\\src\\CredentialsWrapper.php:267)

Previous Error with V6 (It was working perfect until last week)

ERROR: { "message": "Request contains an invalid argument.", "code": 3, "status": "INVALID_ARGUMENT", "details": [ { "@type": 0, "data": "type.googleapis.com\/google.ads.googleads.v6.errors.GoogleAdsFailure" }, { "@type": 0, "data": [ { "errorCode": { "requestError": "UNKNOWN" }, "message": " Version v6 is deprecated. Requests to this version will be blocked." } ] } ] }

SubaKrishnan commented 3 years ago

@fiboknacky Can you please check this issue

fiboknacky commented 3 years ago

Could you include your code too? And what google/gax version is installed in your project?

SubaKrishnan commented 3 years ago

Version Used: google/protobuf (v3.18.0) grpc/grpc (1.39.0) google/gax (v1.9.0) googleads/google-ads-php (v11.0.0)

I had also tried to run your LaravelSampleApp. It's not working too. I getting Error as below

Error

Google\ApiCore\ValidationException Could not construct ApplicationDefaultCredentials From gax

Code:

<?php

   namespace App\Http\Controllers;

    use Carbon\Carbon;
    use Illuminate\Http\Request;
    use Illuminate\View\View;
    use Google\Ads\GoogleAds\Lib\V8\GoogleAdsClient;

class GoogleAdsApiController extends Controller
{

    public function showReportAction(Request $request, GoogleAdsClient $googleAdsClient)
    {

        $customerId = 'XXXXXXXXX';

        // Query
        $previousDateRange = "SELECT customer.currency_code, customer.descriptive_name, metrics.cost_micros, metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpm, metrics.average_cpc, metrics.conversions, metrics.cost_per_conversion, metrics.search_budget_lost_impression_share,  metrics.search_rank_lost_impression_share, metrics.search_impression_share, metrics.conversions_from_interactions_rate, metrics.conversions_value FROM customer WHERE segments.date BETWEEN '2021-09-01' AND '2021-09-20' AND customer.id = $customerId ";

        $previousStream = $googleAdsClient->getGoogleAdsServiceClient()->search( // Error Shouts at this line
            $customerId,
            $previousDateRange
        );

        // Iterating...
        $previousResults = [];
        foreach ($previousStream->iterateAllElements() as $googleAdsRow) {

            // echo $googleAdsRow->serializeToJsonString();
            $previousResults[] = json_decode($googleAdsRow->serializeToJsonString(), true);

        }
        $previousCollection = collect($previousResults);
        $previousCollection->all();
        // $previousCollection->dd();

        return $previousCollection;
    }
}

Screenshot: image

Help me to sort this issue. Thanks in advance

fiboknacky commented 3 years ago

Somehow, I cannot reproduce the issue. Could you attach your composer.lock (the one in the LaravelSampleApp folder) here too?

And could you check the $clientOptions variable before returning the function in this line? Does it have your 'credentials' key set?

SubaKrishnan commented 3 years ago

Composer.Lock file

https://gateway.ipfs.io/ipfs/QmcQkEu176rfxvrif77CJq17SC8nBhGvcTSoKRTZvaXfRU

Can you please check your demo sample Laravel Project is working with your current version?

fiboknacky commented 3 years ago

Can you please check your demo sample Laravel Project is working with your current version?

Yes, it works as usual. As it seems you based your code on ours, but you have modified many things on your part, it's possible that some parts may not be aligned when you did the upgrade.

Have you checked the $clientOptions key I mentioned above yet? And could you try the sample app from scratch based on README, using your credentials again?

SubaKrishnan commented 3 years ago

Thanks for your help. The $clientOptions variable doesn't return any value. In AppServiceProvider, the Oauth hadn't been recognized properly. I had fixed it and upgraded to the current version