简体   繁体   中英

Creating a google adwords API application using OAuth

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM