You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
<?phpnamespaceGoogle\Ads\GoogleAds\Examples\Reporting;
require_once'/var/www/newVendor/vendor/autoload.php';
useGetOpt\GetOpt;
useGoogle\Ads\GoogleAds\Examples\Utils\ArgumentNames;
useGoogle\Ads\GoogleAds\Examples\Utils\ArgumentParser;
useGoogle\Ads\GoogleAds\Lib\V9\GoogleAdsClient;
useGoogle\Ads\GoogleAds\Lib\V9\GoogleAdsClientBuilder;
useGoogle\Ads\GoogleAds\Lib\V9\GoogleAdsException;
useGoogle\Ads\GoogleAds\Lib\V9\GoogleAdsServerStreamDecorator;
useGoogle\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
useGoogle\Ads\GoogleAds\V9\Enums\KeywordMatchTypeEnum\KeywordMatchType;
useGoogle\Ads\GoogleAds\V9\Errors\GoogleAdsError;
useGoogle\Ads\GoogleAds\V9\Services\GoogleAdsRow;
useGoogle\ApiCore\ApiException;
/** * * * * * This example gets keyword performance statistics for the 50 keywords with the most impressions * over the last 7 days. */classGetKeywordStats
{
privateconstCUSTOMER_ID = '2280572092';
publicstaticfunctionmain()
{
// Either pass the required parameters for this example on the command line, or insert them// into the constants above.$options = (newArgumentParser())->parseCommandArguments([
ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT
]);
// Generate a refreshable OAuth2 credential for authentication.$oAuth2Credential = (newOAuth2TokenBuilder())->fromFile('/var/www/google_ads_php.ini')->build();
// Construct a Google Ads client configured from a properties file and the// OAuth2 credentials above.$googleAdsClient = (newGoogleAdsClientBuilder())->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]publicstaticfunctionrunExample(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
The text was updated successfully, but these errors were encountered:
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.
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
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
The text was updated successfully, but these errors were encountered: