Reputation: 1517
I am trying to create a ruby script that will use contents from google AdWords API. However, I am having trouble setting up the OAuth methods. The api docs mention that we need to set up the adwords service in the api console but the AdWords is not mentioned there. What api should I be using for this?
In the adwords_api.yml, following are some of the values that I am using:
:oauth_consumer_key: 123456789046-abcd5ef2ghijkl1mno1p2qrstuvwx1y713.apps.googleusercontent.com
:oauth_consumer_secret: AbcDeF1G_HIJK1a13UKz-PAO
# If you manage or store access token manually, you can specify it here.
#:oauth_token: INSERT_OAUTH_TOKEN_HERE
# If you need to change signature method, specify it here.
#:oauth_signature_method: HMAC-SHA1
# Token secret for HMAC-SHA1 method.
#:oauth_token_secret: INSERT_OAUTH_TOKEN_SECRET_HERE
As I am new to OAuth, are the steps I am following correct?
Upvotes: 1
Views: 1006
Reputation: 727
One of the easiest ways to use OAuth in ruby is with OmniAuth. They have a great community maintained list of RubyGems on their wiki. You should try the omniauth-google-oauth2 gem.
First set up a client id on google. Here's a how to.
Using that gem, I think you can just pass in the adwords api url in the scope. So your config/initializers/omniauth.rb should look something like this.
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, CLIENT_ID, CLIENT_SECRET,
{
name: "adwords",
approval_prompt: "",
scope: "https://adwords.google.com/api/adwords/"
}
end
Then you can link to "/auth/adwords" and that will take the user to the google login.
Upvotes: 2