【问题标题】:Creating a google adwords API application using OAuth使用 OAuth 创建 google adwords API 应用程序
【发布时间】:2013-07-17 05:16:58
【问题描述】:

我正在尝试创建一个将使用来自 google AdWords API 的内容的 ruby​​ 脚本。 但是,我无法设置 OAuth 方法。 api docs 提到我们需要在api console 中设置adwords 服务,但那里没有提到AdWords。我应该为此使用什么 api?

在 adwords_api.yml 中,以下是我使用的一些值:

: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

由于我是 OAuth 新手,我遵循的步骤是否正确?

【问题讨论】:

    标签: ruby oauth-2.0 google-ads-api


    【解决方案1】:

    在 ruby​​ 中使用 OAuth 的最简单方法之一是使用 OmniAuth。他们的 wiki 上有一个很棒的社区维护的 RubyGems 列表。您应该试试 omniauth-google-oauth2 gem。

    首先在google上设置一个client id。 Here's a how to

    使用该 gem,我认为您可以在范围内传入 adwords api url。所以你的 config/initializers/omniauth.rb 应该看起来像这样。

    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
    

    然后您可以链接到“/auth/adwords”,这会将用户带到 google 登录。

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多