googleads / google-ads-ruby

Google Ads API Ruby Client Library
https://developers.google.com/google-ads/api/
Apache License 2.0
70 stars 65 forks source link

Request contains an invalid argument #400

Closed MeisterMichael closed 2 years ago

MeisterMichael commented 2 years ago

Describe the bug:

When making any API call I get the following error: GRPC::InvalidArgument: 3:Request contains an invalid argument.. debug_error_string:{UNKNOWN:Error received from peer ipv4:142.251.40.42:443 {created_time:"2022-07-27T09:00:50.439061-07:00", grpc_status:3, grpc_message:"Request contains an invalid argument."}}

I downloaded the JSON file for my oath credentials, then used the authentication example (https://github.com/googleads/google-ads-ruby/tree/main/examples/authentication) to generate the refresh token, however every time I run any request I get the above error. Screen Shot 2022-07-27 at 9 15 00 AM

Steps to Reproduce:

            # @client = Google::Ads::GoogleAds::GoogleAdsClient.new
            @client = Google::Ads::GoogleAds::GoogleAdsClient.new do |c|
                c.treat_deprecation_warnings_as_errors = false
                c.warn_on_all_deprecations = true
                c.developer_token = ENV['GOOGLE_ADWORDS_API_DEVELOPER_TOKEN']
                c.client_id = ENV['GOOGLE_ADWORDS_APP_CLIENT_ID']
                c.client_secret = ENV['GOOGLE_ADWORDS_APP_CLIENT_SECRET']
                c.refresh_token = ENV['GOOGLE_ADWORDS_OAUTH2_TOKEN_REFRESH_TOKEN']
                c.log_level = 'WARN'
                c.log_target = STDOUT
            end

            @ga_service = @client.service.google_ads

            responses = @client.service.google_ads.search_stream(
                customer_id: @customer_id,
                query: 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id',
            )

Expected behavior: Get a response

Client library version and API version: Client library version: 18.0.0 (not 13.0.0) Google Ads API version: v11

MeisterMichael commented 2 years ago

One other unusual thing is that the generated refresh token begins with "1//" (one then two forward slashes) rather than the usual "1/" (one then a single slash)

mcloonan commented 2 years ago

Version 13.0.0 doesn't support any current API versions. If you don't specify a version manually, then it will use the latest version it knows about, which for 13.0.0 seems to be v8 of the API, not v11.

Update to the newest version of the gem and try again.

MeisterMichael commented 2 years ago

Version 13.0.0 doesn't support any current API versions. If you don't specify a version manually, then it will use the latest version it knows about, which for 13.0.0 seems to be v8 of the API, not v11.

Update to the newest version of the gem and try again.

I know the api version because it is shown in the debug warning.

Screen Shot 2022-07-27 at 9 25 20 AM

MeisterMichael commented 2 years ago

My mistake I am using version 18.0.0 not 13.0.0

MeisterMichael commented 2 years ago

Here are the google gems in my gemlock

    google-ads-googleads (18.0.0)
      gapic-common (~> 0.6.0)
      google-protobuf (>= 3.19.4, < 4.0)
    google-api-client (0.53.0)
      google-apis-core (~> 0.1)
      google-apis-generator (~> 0.1)
    google-apis-core (0.7.0)
      addressable (~> 2.5, >= 2.5.1)
      googleauth (>= 0.16.2, < 2.a)
      httpclient (>= 2.8.1, < 3.a)
      mini_mime (~> 1.0)
      representable (~> 3.0)
      retriable (>= 2.0, < 4.a)
      rexml
      webrick
    google-apis-discovery_v1 (0.11.0)
      google-apis-core (>= 0.7, < 2.a)
    google-apis-generator (0.9.0)
      activesupport (>= 5.0)
      gems (~> 1.2)
      google-apis-core (>= 0.7, < 2.a)
      google-apis-discovery_v1 (~> 0.5)
      thor (>= 0.20, < 2.a)
    google-protobuf (3.21.3-x86_64-darwin)
    googleapis-common-protos (1.3.12)
      google-protobuf (~> 3.14)
      googleapis-common-protos-types (~> 1.2)
      grpc (~> 1.27)
    googleapis-common-protos-types (1.3.2)
      google-protobuf (~> 3.14)
    googleauth (1.2.0)
      faraday (>= 0.17.3, < 3.a)
      jwt (>= 1.4, < 3.0)
      memoist (~> 0.16)
      multi_json (~> 1.11)
      os (>= 0.9, < 2.0)
      signet (>= 0.16, < 2.a)
    grpc (1.48.0-x86_64-darwin)
      google-protobuf (~> 3.19)
      googleapis-common-protos-types (~> 1.0)
MeisterMichael commented 2 years ago

@mcloonan see above updated info

mcloonan commented 2 years ago

The internal error based on that request ID is: RequestError.INVALID_CUSTOMER_ID

Try specifying the customer ID without dashes.

MeisterMichael commented 2 years ago

@mcloonan Thanks! That was driving me mad.

Now I am getting this error. I thought I went through the process, with the authentication example, to get permissions. What am I missing?

...
W, [2022-07-27T09:38:51.652766 #16876]  WARN -- : CID: 5562396321, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v11.services.GoogleAdsService/SearchStream, IsFault: yes, Request ID: 071fztjh6i_gYS10li5RkA
...
GRPC::PermissionDenied: 7:The caller does not have permission. debug_error_string:{UNKNOWN:Error received from peer ipv4:142.251.40.42:443 {grpc_message:"The caller does not have permission", grpc_status:7, created_time:"2022-07-27T09:38:51.650346-07:00"}}
...
mcloonan commented 2 years ago

Again, the internal error message provides more details:

The developer must sign the terms of service. They can be found here: ads.google.com/aw/apicenter

Now I'm just curious why these errors aren't rendering properly for you. They usually do for me when I make requests. I wonder if you make the logging more verbose, will you see these error messages?

MeisterMichael commented 2 years ago

@mcloonan how do I make my logging more verbose?

mcloonan commented 2 years ago

In your config, instead of

c.log_level = 'WARN'

Try:

c.log_level = 'INFO'

Or even:

c.log_level = 'DEBUG'
mcloonan commented 2 years ago

"DEBUG" is the most verbose, but "INFO" should probably be sufficient for this case.