Google Adwords with rails(part 1)

Huang Yu Ti
1 min readNov 15, 2020

Get Client Id and Client Secret and Setting Scope

  1. Go to the Google Api Center, create a web application Credentials

2. Setting redirect url http://localhost:3000/users/auth/google_oauth2/callback ( with devise gem)

3. Went to the Api library, setting Google ads Api is enabled

4. setting scope like

Get developer token

Note: A developer token can be used with multiple client id, but a client ID can be used with only one developer token. The developer_token will auto bundle with client id.

  1. Go to the Adwords page, create a manager account.
  2. Navigating to the Api center ( Tools > setup > Api center )
  3. Need to apply to basic access, otherwise, the token only could read test ads account ( both test ads account or test manager account )

Start Code

I used the https://github.com/googleads/google-ads-ruby.

Get Client All Adword Account ID And Account’s Inform

The refresh_token is accessed by client and

client.service.customer.list_accessible_customers().resource_names

response client’s all adwords’ account id. It looks like customers/XXX-XXX-XXX

The step can success by test developer_token. And

resource_name = client.path.customer(ad_words.gsub("customers/", ""))
customer = client.service.customer.get_customer(resource_name: resource_name)

response account’s inform. client.path.customer({ customer's id}) . It inputs only the number.

The step needs basic developer_token( be reviewed ), or it will response auth error.

Finally, We finished Adword Api start. Next time we will get campagin’ s cost amd search by time.

reference:

  1. https://developers.google.com/google-ads/api/docs/first-call/overview
  2. https://github.com/heartcombo/devise
  3. https://github.com/googleads/google-ads-ruby
  4. https://developers.google.com/google-ads/api/docs/release-notes

--

--