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

google ads migration issue #727

Closed
fil79 opened this issue Jan 31, 2022 · 1 comment
Closed

google ads migration issue #727

fil79 opened this issue Jan 31, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@fil79
Copy link

fil79 commented Jan 31, 2022

Hi
I am upgrading from googleAdWords API to googleAds API. I am always getting a fatal error when i try to run the sample code

<?php

namespace Google\Ads\GoogleAds\Examples\Reporting;

require_once '/var/www/newVendor/vendor/autoload.php';



use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\V9\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V9\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V9\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\V9\GoogleAdsServerStreamDecorator;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V9\Enums\KeywordMatchTypeEnum\KeywordMatchType;
use Google\Ads\GoogleAds\V9\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V9\Services\GoogleAdsRow;
use Google\ApiCore\ApiException;



/**
 * 
 * 
 * 
 * 
 * This example gets keyword performance statistics for the 50 keywords with the most impressions
 * over the last 7 days.
 */
class GetKeywordStats
{
    private const CUSTOMER_ID = '2280572092';

    public static function main()
    {
        // Either pass the required parameters for this example on the command line, or insert them
        // into the constants above.
        $options = (new ArgumentParser())->parseCommandArguments([
            ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT
        ]);

        // Generate a refreshable OAuth2 credential for authentication.
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile('/var/www/google_ads_php.ini')->build();

        // Construct a Google Ads client configured from a properties file and the
        // OAuth2 credentials above.
        $googleAdsClient = (new GoogleAdsClientBuilder())->fromFile('/var/www/google_ads_php.ini')
            ->withTransport('rest')
            ->withOAuth2Credential($oAuth2Credential)
            ->build();

        try {
            self::runExample(
                $googleAdsClient,
                $options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID
            );
        } catch (GoogleAdsException $googleAdsException) {
            printf(
                "Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
                $googleAdsException->getRequestId(),
                PHP_EOL,
                PHP_EOL
            );
            foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
                /** @var GoogleAdsError $error */
                printf(
                    "\t%s: %s%s",
                    $error->getErrorCode()->getErrorCode(),
                    $error->getMessage(),
                    PHP_EOL
                );
            }
            exit(1);
        } catch (ApiException $apiException) {
            printf(
                "ApiException was thrown with message '%s'.%s",
                $apiException->getMessage(),
                PHP_EOL
            );
            exit(1);
        }
    }

    /**
     * Runs the example.
     *
     * @param GoogleAdsClient $googleAdsClient the Google Ads API client
     * @param int $customerId the customer ID
     */
    // [START get_keyword_stats]
    public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId)
    {
        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        // Creates a query that retrieves all keyword statistics.
        $query =
            "SELECT campaign.id, "
                . "campaign.name, "
                . "ad_group.id, "
                . "ad_group.name, "
                . "ad_group_criterion.criterion_id, "
                . "ad_group_criterion.keyword.text, "
                . "ad_group_criterion.keyword.match_type, "
                . "metrics.impressions, "
                . "metrics.clicks, "
                . "metrics.cost_micros "
            . "FROM keyword_view "
            . "WHERE segments.date DURING LAST_7_DAYS "
                . "AND campaign.advertising_channel_type = 'SEARCH' "
                . "AND ad_group.status = 'ENABLED' "
                . "AND ad_group_criterion.status IN ('ENABLED', 'PAUSED') "
            . "ORDER BY metrics.impressions DESC "
            . "LIMIT 10";

        // Issues a search stream request.
        /** @var GoogleAdsServerStreamDecorator $stream */
        $stream =
            $googleAdsServiceClient->searchStream($customerId, $query);

        // Iterates over all rows in all messages and prints the requested field values for
        // the keyword in each row.
        foreach ($stream->iterateAllElements() as $googleAdsRow) {
            /** @var GoogleAdsRow $googleAdsRow */
            $campaign = $googleAdsRow->getCampaign();
            $adGroup = $googleAdsRow->getAdGroup();
            $adGroupCriterion = $googleAdsRow->getAdGroupCriterion();
            $metrics = $googleAdsRow->getMetrics();
            printf(
                "Keyword text '%s' with "
                . "match type %s "
                . "and ID %d "
                . "in ad group '%s' "
                . "with ID %d "
                . "in campaign '%s' "
                . "with ID %d "
                . "had %d impression(s), "
                . "%d click(s), "
                . "and %d cost (in micros) "
                . "during the last 7 days.%s",
                $adGroupCriterion->getKeyword()->getText(),
                KeywordMatchType::name($adGroupCriterion->getKeyword()->getMatchType()),
                $adGroupCriterion->getCriterionId(),
                $adGroup->getName(),
                $adGroup->getId(),
                $campaign->getName(),
                $campaign->getId(),
                $metrics->getImpressions(),
                $metrics->getClicks(),
                $metrics->getCostMicros(),
                PHP_EOL
            );
        }
    }
    // [END get_keyword_stats]
}

GetKeywordStats::main();

error log: [31-Jan-2022 18:54:17] PHP Fatal error: Uncaught Google\ApiCore\ValidationException: Failed to build request, as the provided path (google.ads.googleads.v9.services.GoogleAdsService/SearchStream) was not found in the configuration. in /var/www/newVendor/vendor/google/gax/src/RequestBuilder.php:80 Stack trace: #0 /var/www/newVendor/vendor/google/gax/src/Transport/RestTransport.php(160): Google\ApiCore\RequestBuilder->build() #1 /var/www/newVendor/vendor/google/gax/src/GapicClientTrait.php(608): Google\ApiCore\Transport\RestTransport->startServerStreamingCall() #2 /var/www/newVendor/vendor/google/gax/src/Middleware/CredentialsWrapperMiddleware.php(61): Google\Ads\GoogleAds\V9\Services\Gapic\GoogleAdsServiceGapicClient->Google\ApiCore{closure}() #3 /var/www/newVendor/vendor/google/gax/src/Middleware/FixedHeaderMiddleware.php(66): Google\ApiCore\Middleware\CredentialsWrapperMiddleware->__invoke() #4 /var/www/newVendor/vendor/google/gax/src/Middleware/RetryMiddleware.php(85): Google\ApiCore\Middleware\FixedHeaderMiddleware->__invoke() #5 /var/www/newVe in /var/www/newVendor/vendor/google/gax/src/RequestBuilder.php on line 80

Thanks in advance

@fil79 fil79 added question Further information is requested triage Need triage labels Jan 31, 2022
@PierrickVoulet
Copy link
Collaborator

Hi @fil79 - I believe this is the same issue as another one your opened #726. This is a known issue, please check #722 and let us know if that does not help.

@PierrickVoulet PierrickVoulet self-assigned this Jan 31, 2022
@PierrickVoulet PierrickVoulet added bug Something isn't working and removed question Further information is requested triage Need triage labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants