Closed rdonahueah closed 2 months ago
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
Could you please share the whole code?
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);
}
}
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.
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
975▕ if (is_string($value) && trim($value) !== $value) {
976▕ throw new GPBDecodeException(
977▕ "Invalid data type for int64 field");
978▕ }
➜ 979▕ if (bccomp($value, "9223372036854775807") > 0) {
980▕ throw new GPBDecodeException(
981▕ "Int64 too large");
982▕ }
983▕ if (bccomp($value, "-9223372036854775808") < 0) {
What code did you run? And what's the error message?
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
975▕ if (is_string($value) && trim($value) !== $value) {
976▕ throw new GPBDecodeException(
977▕ "Invalid data type for int64 field");
978▕ }
➜ 979▕ if (bccomp($value, "9223372036854775807") > 0) {
980▕ throw new GPBDecodeException(
981▕ "Int64 too large");
982▕ }
983▕ if (bccomp($value, "-9223372036854775808") < 0) {
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?
Added in the bcmath extension which resolves the runtime error but still getting the typing errors.
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?
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
So, did you try what I asked previously. What did you get as a result?
Closing due to inactivity. Feel free to reopen this if you still need help.
[DO NOT INCLUDE ANY PERSONAL OR SENSITIVE DATA - MAKE SURE TO REDACT CONTENT WHEN NECESSARY]
Your client library and Google Ads API versions:
v22.1.0
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
Despite all imports for the above code using V16 library, the search method on the
$googleAdsServiceClient
complains that we are not passing in aSearchGoogleAdsRequest
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: