【问题标题】:Creating OAuth connection for Google Calendar API为 Google Calendar API 创建 OAuth 连接
【发布时间】:2012-04-19 19:55:02
【问题描述】:

我正在使用这个 gem https://github.com/unixcharles/google_calendar_api_v2 它基于https://github.com/oauth/oauth-ruby

在客户端类中创建如下连接:

  def initialize(consumer_key, consumer_secret, token, token_secret)
    consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {
      :site               => "https://www.google.com",
      :scheme             => :header
    })
    @connection = OAuth::AccessToken.new(consumer,token, token_secret)

    @calendars = Calendar.new(@connection)
  end

对于 consumer_key,我是否将 Google API 控制台列出的内容列为“客户端 ID”? 对于 consumer_secret,我是否将 Google API 控制台列出的内容列为“客户端密码”? 我知道令牌是我在 OAuth 身份验证后得到的。 我假设我将 token_secret 设置为 "" ?

这就是我正在做的事情,我不断得到:

"GoogleCalendarApiV2::AuthenticationError (GoogleCalendarApiV2::AuthenticationError):" 

当我打电话时:

  client = GoogleCalendarApiV2::Client.new {'Client ID'}, {'Client secret'}, params[:access_token], ""
  calendar = client.calendars.all

知道发生了什么吗?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 oauth google-api


    【解决方案1】:

    客户端 ID 是您的域。

    应该是这样的:

    client = GoogleCalendarApiV2::Client.new 'teambox.com', 'some_secret_key_for_your_domain', 'oauth_token_for_the_user', 'oauth_secret_for_the_user'
    

    请记住,此 Gem 用于 OAuth1 和 APIv2,较新的 APIv3 不能这样工作。它使用不同的 OAuth2。

    【讨论】:

      【解决方案2】:

      新的 Google APIs Ruby 客户端库支持日历 API v3:

      http://code.google.com/p/google-api-ruby-client/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多