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

Error on getKeywordPlanIdeaServiceClient #901

Closed GBonnaire closed 1 year ago

GBonnaire commented 1 year ago

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

Your client library and Google Ads API versions:

Your environment: PHP 8.1.18 / Symfony 6.2

Description of the bug:

I try to use function getKeywordPlanIdeaServiceClient with follow example, and i have this error :

Attempted to call function "bccomp" from namespace "Google\Protobuf\Internal"

$urlSeed = new UrlSeed(['url' => $pageUrl]);

        $languageId = 1002; // Fr
        $locationIds = [1006094]; // Paris

        $keywordPlanIdeaServiceClient = $googleAdsClient->getKeywordPlanIdeaServiceClient();

        $requestOptionalArgs = [];

        $requestOptionalArgs['urlSeed'] = $urlSeed;

        $geoTargetConstants =  array_map(function ($locationId) {
            return ResourceNames::forGeoTargetConstant($locationId);
        }, $locationIds);

        try {
            $options = [
                    // Set the language resource using the provided language ID.
                    'language' => ResourceNames::forLanguageConstant($languageId),
                    'customerId' => $customerId,
                    // Add the resource name of each location ID to the request.
                    'geoTargetConstants' => $geoTargetConstants,
                    // Set the network. To restrict to only Google Search, change the parameter below to
                    //'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH,
                    'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH_AND_PARTNERS,
                ] + $requestOptionalArgs;
            $response = $keywordPlanIdeaServiceClient->generateKeywordIdeas($options);
        } catch (GoogleAdsException $googleAdsException) {
            dump($googleAdsException);
        } catch (ApiException $apiException) {
            dump($apiException);
        }

        // Iterate over the results and print its detail.
        $result= array();
        foreach ($response->iterateAllElements() as $result) {
            /** @var GenerateKeywordIdeaResult $result */
            // Note that the competition printed below is enum value.
            // For example, a value of 2 will be returned when the competition is 'LOW'.
            // A mapping of enum names to values can be found at KeywordPlanCompetitionLevel.php.
            $result[] = sprintf(
                "Keyword idea text '%s' has %d average monthly searches and competition as %d.%s",
                $result->getText(),
                is_null($result->getKeywordIdeaMetrics()) ?
                    0 : $result->getKeywordIdeaMetrics()->getAvgMonthlySearches(),
                is_null($result->getKeywordIdeaMetrics()) ?
                    0 : $result->getKeywordIdeaMetrics()->getCompetition(),
                PHP_EOL
            );
        }

Have you and idea why i have this error and how fix this ? Steps to reproduce:

Expected behavior:

Request/Response Logs:

Anything else we should know about your project / environment:

fiboknacky commented 1 year ago

Attempted to call function "bccomp" from namespace "Google\Protobuf\Internal"

Does it show a file name and line number? And what's your protobuf version? Is it C or PHP implementation?

GBonnaire commented 1 year ago

Yes Message.php Line 1002

GBonnaire commented 1 year ago

I will check PHP implementation

GBonnaire commented 1 year ago

With PECL Protobuf, it's work. Thanks 😊