javagoogle-ads-api

"Fault: Connection closed after GOAWAY. HTTP/2 error code: NO_ERROR, debug data: session_timed_out" when sending request to Google Ads API


I am using google-ads-java library to fetch campaigns from my Google Ads account follow this Google Ads API tutorial.
Everything is smooth with my ads.properties setting (clientId, clientSecret, refreshToken, developerToken, loginCustomerId)

But when it runs, it doesn't output anything then after a while, it shows an error:

c.g.ads.googleads.lib.request.summary    : FAILURE REQUEST SUMMARY. Method: google.ads.googleads.v15.services.GoogleAdsService/SearchStream, Endpoint: googleads.googleapis.com:443, CustomerID: {my_ad_manager_id}, RequestID: null, ResponseCode: UNAVAILABLE, Fault: Connection closed after GOAWAY. HTTP/2 error code: NO_ERROR, debug data: session_timed_out.
c.g.ads.googleads.lib.request.detail     : FAILURE REQUEST DETAIL.

Request
-------
MethodName: google.ads.googleads.v15.services.GoogleAdsService/SearchStream
Endpoint: googleads.googleapis.com:443
Headers: {developer-token=REDACTED, login-customer-id={my_ad_manager_id}, x-goog-api-client=gl-java/19.0.2 gccl/28.0.0 gapic/28.0.0 gax/2.32.0 grpc/1.56.1}
Body: customer_id: "{my_ad_account_id}"
query: "SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id"

Response
--------
Headers: null
Body: null
Failure message: null
Status: Status{code=UNAVAILABLE, description=Connection closed after GOAWAY. HTTP/2 error code: NO_ERROR, debug data: session_timed_out, cause=null}.

No further info at my local.
When I check the Google Cloud APIs & Services Dashboard, it shows all the requests got 403 error


Solution

  • I solved my issue.

    Firstly, google-ads-java client can't get the response from Google API servers because of my company's security. The SSL cert has been changed to Netskope self-cert. Tested on my personal computer and everything is fine. When I try with curl, the error is clear.

    "@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
    "errors": [
        {
            "errorCode": {
                "authorizationError": "DEVELOPER_TOKEN_NOT_APPROVED"
            },
            "message": "The developer token is only approved for use with test accounts. To access non-test accounts, apply for Basic or Standard access."
        }
    ]
    

    I need to create a new Test Ad Manager account and create a Test Client Ad account inside follow this guide: https://developers.google.com/google-ads/api/docs/best-practices/test-accounts

    Secondly, I can't create a Test Client Ad account via Google Ads GUI, it doesn't allow us to create with error (same as in: https://support.google.com/google-ads/thread/249148718/can-t-create-a-test-client-account?hl=en)

    To create new accounts, link an existing account
    This needs to be a Google Ads account that
    * has spent more than $1,000
    * has a history of policy compliance
    

    Fortunately, we can create a Test Client Ad account via API with curl by this guide: https://developers.google.com/google-ads/api/rest/examples#creating_accounts

    curl --location 'https://googleads.googleapis.com/v15/customers/{Your_test_ad_manager_customer_id}:createCustomerClient' \
    --header 'Content-Type: application/json' \
    --header 'developer-token: {Your_test_developer_token}' \
    --header 'login-customer-id: {Your_test_ad_manager_customer_id}' \
    --header 'Authorization: Bearer {Your_OAuth2_access_token}' \
    --data '{
        "customerClient": {
            "descriptiveName": "My Test Client",
            "currencyCode": "JPY",
            "timeZone": "Asia/Tokyo"
        }
    }'