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

API endpoint unavailable #895

Closed willybahuaud closed 1 year ago

willybahuaud commented 1 year ago

Hello,

I'm contacting you regarding an issue that I submitted to Google Ads API support, but they redirected me here because it's related to the library. To summarize the problem: requests to the API randomly fail to be sent. When I activate the log file, here's what I get:

[2023-04-12T07:06:49.808346+00:00] google-ads.notice: Request
-------
Method Name: /[google.ads.googleads.v13.services.KeywordPlanIdeaService/GenerateKeywordIdeas](https://github.com/googleads/google-ads-php/issues/google.ads.googleads.v13.services.KeywordPlanIdeaService/GenerateKeywordIdeas)
Host: [googleads.googleapis.com](https://github.com/googleads/google-ads-php/issues/googleads.googleapis.com)
Headers: {
    "x-goog-api-client": "gl-php\/7.4.25 gccl\/18.0.0 gapic\/18.0.0 gax\/1.12.1 grpc\/1.46.0RC2 rest\/1.12.1",
    "x-goog-request-params": "customer_id=xxxxxxxxx",
    "developer-token": "REDACTED"
}
Request:
{"customerId":"xxxxxxxxx","language":"languageConstants/1002","geoTargetConstants":["geoTargetConstants/2250"],"keywordPlanNetwork":"GOOGLE_SEARCH","keywordSeed":{"keywords":["massage 3D"]}}

Response
-------
Headers: []

Fault
-------
Status code: 14
Details: 403:Forbidden
Failure: {}

I have neither a request ID nor an error message, just gRPC indicating that the requested endpoint is unreachable. With the API's retry mechanism, the endpoint is continuously pinged for 24 minutes, but it doesn't change anything: the API endpoint never responds. However, the same request can go through without any problems an hour later.

So I disabled the retry (using a retrySetting argument in my request), but I'm struggling to understand why the API randomly rejects my requests without even returning an error code. Could this be due to an update of the library or the API (I recently updated it from V10 to V13) or to gRPC/protobuf (which I didn't update)? The problem has been especially present for the past month, whereas the following code used to work without any issues:

use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V13\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Util\V13\ResourceNames;
use Google\Ads\GoogleAds\V13\Enums\KeywordPlanNetworkEnum\KeywordPlanNetwork;
use Google\Ads\GoogleAds\V13\Services\KeywordSeed;

$customerId = 'xxxxxxxxx'; // my hidden ID ;-)
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$googleAdsClient = (new GoogleAdsClientBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();

$keyword = 'avion';
$keywordPlanIdeaServiceClient = $googleAdsClient->getKeywordPlanIdeaServiceClient();
$locationIds = [ 2250 ]; // France
$geoTargetConstants =  array_map(function ($locationId) {
    return ResourceNames::forGeoTargetConstant($locationId);
}, $locationIds);
$response = $keywordPlanIdeaServiceClient->generateKeywordIdeas(
    [
        'language'             => ResourceNames::forLanguageConstant( 1002 ), // French
        'customerId'         => $customerId,
        'geoTargetConstants' => $geoTargetConstants,
        'keywordPlanNetwork' => KeywordPlanNetwork::GOOGLE_SEARCH,
        'keywordSeed'        => new KeywordSeed(['keywords' => [$keyword]]),
        'retrySettings'      => [
            'retriesEnabled' => false,
        ]
    ]
);

Do you have any suggestions that could help me get the library working?

I thank you in advance for your ideas and your help.

fiboknacky commented 1 year ago

I can run GenerateKeywordIdeas.php successfully without any issues.

Did you change any networking connections recently, run your code behind any firewalls or in a VM or shared server? If so, you might need to check if there is any settings blocking your requests.

willybahuaud commented 1 year ago

Thanks @fiboknacky I contacted my host who informed me that they have had a major issue for the past 20 days communicating with Google APIs over IPv6, and they recommend that I force IPv4 when connecting to the API. I don't see a specific option in the library to force IPv4, is it possible, or is it a setting to be done at the gRPC level?

fiboknacky commented 1 year ago

We don't have a way to directly specify that option in this library. Could you reach out to the grpc team and ask for this feature?