googleads / google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
297 stars 229 forks source link

how to change client_customer_id programmatically #159

Closed evrenios closed 8 months ago

evrenios commented 5 years ago

Hello, i have a manager account which have multiple clients attached to it.

any given time, i need to be able to do different api calls for different client ids.

currently i can only do api calls with default api object that loads from adwords_api.yml with

adwords = AdwordsApi::Api.new

i tried to create custom objects with

adwords = AdwordsApi::Api.new({
  :authentication => {
      :method => 'OAuth2',
      :oauth2_client_id => 'xxxxx',
      :oauth2_client_secret => 'xxxxx',
      :developer_token => 'xxx',
      :client_customer_id => 'xxx',
      :user_agent => 'xxxx'
  },
  :service => {
    :environment => 'PRODUCTION'
  }
})

and call authorize method on it but i'm receiving AdsCommon::Errors::OAuth2VerificationRequired

i even tried to init with the client id that i wrote to yaml file, and still received that error.

than i tried to give the yaml config specifically, which failed again.

adwords = AdwordsApi::Api.new({
  :authentication => {
      :method => 'OAuth2',
      :oauth2_client_id => 'xxxxxxx',
      :oauth2_client_secret => 'xxxxx',
      :developer_token => 'xxxxx,
      :client_customer_id => 'xxxxx',
      :user_agent => 'xxxx'
  },
  :oauth2_token => {
    :refresh_token => 'xxxxx,
    :access_token => 'xxxxx'
  },
  :service => {
    :environment => 'PRODUCTION'
  }
})

i also tried to use

use_runtime_config.rb

in https://github.com/googleads/google-api-ads-ruby/blob/master/adwords_api/examples/v201809/misc/use_runtime_config.rb

which gave me this error

AdwordsApi::V201809::CustomerService::ApiException: [AuthenticationError.OAUTH_TOKEN_HEADER_INVALID @ ; trigger:'<null>']

how can i accomplish this need.

Thanks.

mcloonan commented 5 years ago

I'm not sure why those aren't working, but the easiest way to do this would probably be to call:

adwords.credential_handler.set_credential('client_customer_id', new_value)

Let me know if that works out!

evrenios commented 5 years ago

nope didnt work

gautam417 commented 4 years ago

You need to add the issued_at and expires_in attributes for the oauth2_token or else it breaks.

                        oauth2_token:         {
                        access_token:  "xxx",
                        refresh_token: "xxx",
                        issued_at:     "xxx",
                        expires_in:    0
                    },