Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V16 Library expecting instances from V14 Classes #1017

Closed
rdonahueah opened this issue Apr 26, 2024 · 13 comments
Closed

V16 Library expecting instances from V14 Classes #1017

rdonahueah opened this issue Apr 26, 2024 · 13 comments
Labels
bug Something isn't working triage Need triage

Comments

@rdonahueah
Copy link

[DO NOT INCLUDE ANY PERSONAL OR SENSITIVE DATA - MAKE SURE TO REDACT CONTENT WHEN NECESSARY]

Your client library and Google Ads API versions:

  • Client library version: v22.1.0
  • Google Ads API version: V16

Your environment:

Description of the bug:

When using only the V16 version of the library the an error is thrown requesting an instance to be passed in from the V14 library

Steps to reproduce:

Code mostly pulled from the examples in repo

$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile($this->config)->build();

$googleAdsClient = (new GoogleAdsClientBuilder())
            ->fromFile($this->config)
            ->withOAuth2Credential($oAuth2Credential)
            ->withLoginCustomerId("123456789")
            ->usingGapicV2Source(true)
            ->build();

// Creates the Google Ads Service client.
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();

 // Creates a query that retrieves all child accounts of the manager specified in search calls below.
$query = 'SELECT customer_client.client_customer, customer_client.level,'
            . ' customer_client.manager, customer_client.descriptive_name,'
            . ' customer_client.currency_code, customer_client.time_zone,'
            . ' customer_client.id FROM customer_client WHERE customer_client.level <= 1';

        
 $searchResult = $googleAdsServiceClient->search(SearchGoogleAdsRequest::build("123456789", $query));
        

Despite all imports for the above code using V16 library, the search method on the $googleAdsServiceClient complains that we are not passing in a SearchGoogleAdsRequest from the V14 library, then changing to import to the v14 library it then complains as it expects two strings passed instead.

Expected behavior:

Expect the method to accept the instance of SearchGoogleAdsRequest from the v16 library as shown in example code provided from the Google repo

Request/Response Logs:

Anything else we should know about your project / environment:

@rdonahueah rdonahueah added bug Something isn't working triage Need triage labels Apr 26, 2024
@rdonahueah
Copy link
Author

Full error shown below

Argument '1' passed to search() is expected to be of type Google\Ads\GoogleAds\V14\Services\SearchGoogleAdsRequest, Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest givenPHP(PHP0406)
class Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest extends \Google\Protobuf\Internal\Message
Request message for

[GoogleAdsService.Search][google.ads.googleads.v16.services.GoogleAdsService.Search].

Generated from protobuf message google.ads.googleads.v16.services.SearchGoogleAdsRequest

@fiboknacky
Copy link
Member

Could you please share the whole code?

@rdonahueah
Copy link
Author

rdonahueah commented Apr 29, 2024

Could you please share the whole code?

<?php

namespace App\Libraries;

use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V16\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\V16\Services\Client\GoogleAdsServiceClient;
use Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest;
class GoogleAdwordsClient
{
    public $config;
    public GoogleAdsServiceClient $serviceClient;

    public $ADWORDS_MANAGER_ACCOUNT_ID = "1234567";

    public function __construct()
    {
        $rootDirectory = base_path();
        $this->config = $rootDirectory . '/secure/google_ads_php.ini';
    }

    public function getHeierarchy()
    {
        // Generate a refreshable OAuth2 credential for authentication.
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile($this->config)->build();

        $googleAdsClient = (new GoogleAdsClientBuilder())
            ->fromFile($this->config)
            ->withOAuth2Credential($oAuth2Credential)
            ->withLoginCustomerId($this->ADWORDS_MANAGER_ACCOUNT_ID)
            ->usingGapicV2Source(true)
            ->build();

        // Creates the Google Ads Service client.
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();

        // Creates a query that retrieves all child accounts of the manager specified in search
        // calls below.
        $query = 'SELECT customer_client.client_customer, customer_client.level,'
            . ' customer_client.manager, customer_client.descriptive_name,'
            . ' customer_client.currency_code, customer_client.time_zone,'
            . ' customer_client.id FROM customer_client WHERE customer_client.level <= 1';

        
        $result = $googleAdsServiceClient->search(SearchGoogleAdsRequest::build($this->ADWORDS_MANAGER_ACCOUNT_ID, $query));

        dd($result);
    }


}

@fiboknacky
Copy link
Member

Could you try running GetCampaigns?
Does it work?

Your code above looks okay to me. It shouldn't rely on any V14 classes. Actually, most of the classes you're using (e.g., SearchGoogleAdsRequest) are automatically generated based on the protobuf definitions and we've not changed it for months.
You may also try removing the directory of this repository in vendor and run composer install or composer update again to force it to re-download this repository. Most of the time, it'll be fixed.

@rdonahueah
Copy link
Author

Running the code just results in this error. Not sure if this gives anymore insight though.

at vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:979
    975if (is_string($value) && trim($value) !== $value) {
    976throw new GPBDecodeException(
    977▕                        "Invalid data type for int64 field");
    978▕                 }
  ➜ 979if (bccomp($value, "9223372036854775807") > 0) {
    980throw new GPBDecodeException(
    981▕                         "Int64 too large");
    982▕                 }
    983if (bccomp($value, "-9223372036854775808") < 0) {
    

@fiboknacky
Copy link
Member

What code did you run? And what's the error message?

@rdonahueah
Copy link
Author

getHeierarchy

Sorry my copy left out the error message portion, this was runningt he getHeirarchy method on the class I posted.

 Error 

  Call to undefined function Google\Protobuf\Internal\bccomp()

  at vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:979
    975if (is_string($value) && trim($value) !== $value) {
    976throw new GPBDecodeException(
    977▕                        "Invalid data type for int64 field");
    978▕                 }
  ➜ 979if (bccomp($value, "9223372036854775807") > 0) {
    980throw new GPBDecodeException(
    981▕                         "Int64 too large");
    982▕                 }
    983if (bccomp($value, "-9223372036854775808") < 0) {

@fiboknacky
Copy link
Member

Usually, it shouldn't trigger that part. It looks like you need to install bcmath as described in composer.json too.

So, do you still get the error about v14 like you mentioned above?

@rdonahueah
Copy link
Author

rdonahueah commented May 6, 2024

Added in the bcmath extension which resolves the runtime error but still getting the typing errors.

@fiboknacky
Copy link
Member

What typing errors do you mean?
Could you summarize what errors are you still getting? You mentioned that you got an error about V14 classes referred to by V16 classes. Then, you mentioned the undefined error of bccomp.
Which one are you getting now?

@rdonahueah
Copy link
Author

The main error is this. II wasnt sure if the bcmath package was related because it had not yet been installed but now that its working that isnt the case and I am still getting the type errors.

Argument '1' passed to search() is expected to be of type Google\Ads\GoogleAds\V14\Services\SearchGoogleAdsRequest, Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest givenPHP(PHP0406)
class Google\Ads\GoogleAds\V16\Services\SearchGoogleAdsRequest extends \Google\Protobuf\Internal\Message
Request message for

[GoogleAdsService.Search][google.ads.googleads.v16.services.GoogleAdsService.Search].

Generated from protobuf message google.ads.googleads.v16.services.SearchGoogleAdsRequest

@fiboknacky
Copy link
Member

So, did you try what I asked previously. What did you get as a result?

@fiboknacky
Copy link
Member

Closing due to inactivity. Feel free to reopen this if you still need help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Need triage
Projects
None yet
Development

No branches or pull requests

2 participants