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

Header values must be of type string or array (ArgumentError) #425

Closed voets closed 10 months ago

voets commented 1 year ago

I'm starting out with Ads API , ruby client, to see if I can report offline conversions from our server to our google account. I've setup a service account and stored the credentials json file. I've modified this exampe script https://developers.google.com/google-ads/api/samples/get-ad-groups a little to use the json file as a keyfile

When running the script it raises the error: Header values must be of type string or array (ArgumentError)

Here are the results from the commandline: W, [2023-02-16T15:30:00.137367 #91412] WARN -- : CID: 3362200146, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v12.services.GoogleAdsService/Search, IsFault: yes, Request ID: N/A I, [2023-02-16T15:30:00.137681 #91412] INFO -- : Outgoing request: Headers: {"developer-token":"REDACTED","x-goog-api-client":"gl-ruby/2.7.7 gccl/20.0.0 gax/0.17.1 gapic/20.0.0 grpc/1.52.0 pb/3.21.12","x-goog-request-params":"customer_id=3362200146"} Payload: {"customerId":"3362200146","query":"SELECT campaign.id, ad_group.id, ad_group.name FROM ad_group","pageSize":1000} I, [2023-02-16T15:30:00.137758 #91412] INFO -- : Incoming response (errors): ArgumentError(Header values must be of type string or array): called from: script/google_test2.rb:23:in get_ad_groups' Traceback (most recent call last): 27: from bin/rails:4:in ' 26: from bin/rails:4:in require' 25: from /usr/local/lib/ruby/gems/2.7/gems/railties-6.1.3.2/lib/rails/commands.rb:18:in' 24: from /usr/local/lib/ruby/gems/2.7/gems/railties-6.1.3.2/lib/rails/command.rb:50:in invoke' 23: from /usr/local/lib/ruby/gems/2.7/gems/railties-6.1.3.2/lib/rails/command/base.rb:69:inperform' 22: from /usr/local/lib/ruby/gems/2.7/gems/thor-1.2.1/lib/thor.rb:392:in dispatch' 21: from /usr/local/lib/ruby/gems/2.7/gems/thor-1.2.1/lib/thor/invocation.rb:127:ininvoke_command' 20: from /usr/local/lib/ruby/gems/2.7/gems/thor-1.2.1/lib/thor/command.rb:27:in run' 19: from /usr/local/lib/ruby/gems/2.7/gems/railties-6.1.3.2/lib/rails/commands/runner/runner_command.rb:42:inperform' 18: from /usr/local/lib/ruby/gems/2.7/gems/railties-6.1.3.2/lib/rails/commands/runner/runner_command.rb:42:in load' 17: from script/google_test2.rb:51:in' 16: from script/google_test2.rb:23:in get_ad_groups' 15: from /usr/local/lib/ruby/gems/2.7/gems/google-ads-googleads-20.0.0/lib/google/ads/google_ads/service_wrapper.rb:50:inmethod_missing' 14: from /usr/local/lib/ruby/gems/2.7/gems/google-ads-googleads-20.0.0/lib/google/ads/google_ads/service_wrapper.rb:50:in public_send' 13: from /usr/local/lib/ruby/gems/2.7/gems/google-ads-googleads-20.0.0/lib/google/ads/google_ads/v12/services/google_ads_service/client.rb:263:insearch' 12: from /usr/local/lib/ruby/gems/2.7/gems/gapic-common-0.17.1/lib/gapic/grpc/service_stub.rb:156:in call_rpc' 11: from /usr/local/lib/ruby/gems/2.7/gems/gapic-common-0.17.1/lib/gapic/grpc/service_stub/rpc_call.rb:123:incall' 10: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/client_stub.rb:173:in block in request_response' 9: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/interceptors.rb:175:inintercept!' 8: from /usr/local/lib/ruby/gems/2.7/gems/google-ads-googleads-20.0.0/lib/google/ads/google_ads/interceptors/logging_interceptor.rb:53:in request_response' 7: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/interceptors.rb:177:inblock in intercept!' 6: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/interceptors.rb:175:in intercept!' 5: from /usr/local/lib/ruby/gems/2.7/gems/google-ads-googleads-20.0.0/lib/google/ads/google_ads/interceptors/error_interceptor.rb:65:inrequest_response' 4: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/interceptors.rb:181:in block in intercept!' 3: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/interceptors.rb:178:inblock (2 levels) in intercept!' 2: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/client_stub.rb:174:in block (2 levels) in request_response' 1: from /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/active_call.rb:373:inrequest_response' /usr/local/lib/ruby/gems/2.7/gems/grpc-1.52.0/src/ruby/lib/grpc/generic/active_call.rb:373:in `run_batch': Header values must be of type string or array (ArgumentError)

I'm using ruby 2.7 as you can see, with rails 6.1.3.2 on FreeBSD 12.4-RELEASE r372781

The request headers show up as a hash in the logging, but all key/value header pairs look fine to me. So I hope you can tell me what is going wrong here , since I have no clue what could be causing this

mcloonan commented 1 year ago

It's hard to tell without full context of what your script is doing. What I would suggest is start with the example exactly as we wrote it, confirm that that's working, and then re-implement your changes one at a time until you discover which step caused the issue. From there I may be able to provide more help or you may even figure it out yourself.

siav92 commented 1 year ago

I'm also authenticating using a service account keyfile and getting the same error if I don't set the developer_token. Do you need to set that even if you're using a service account?

mcloonan commented 10 months ago

Yes, developer token is always required.

Service account and/or refresh token authenticates that you are allowed to access the Google Ads account. Developer token authenticates that you are allowed to use the API.

Both are required for every request.