Google Adwords with rails(part 1)
Get Client Id and Client Secret and Setting Scope
- 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.
- Go to the Adwords page, create a manager account.
- Navigating to the Api center ( Tools > setup > Api center )
- 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.