【问题标题】:Google Calendar API insert event without auth Rails没有身份验证 Rails 的 Google Calendar API 插入事件
【发布时间】:2016-08-03 15:16:20
【问题描述】:

我需要在没有用户身份验证的情况下在我的日历中插入事件。

变量:

  OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
  APPLICATION_NAME = 'Google Calendar API Ruby Quickstart'
  CLIENT_SECRETS_PATH = './lib/client_secret.json'
  CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
                               "calendar-ruby-quickstart.yaml")
  SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR

  def initialize(meeting_data)
   @meeting_data = meeting_data
  end

授权过程:

  def authorize
    FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))

    client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
    token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
    authorizer = Google::Auth::UserAuthorizer.new(
        client_id, SCOPE, token_store)
    user_id = '2'
    credentials = authorizer.get_credentials(user_id)
    if credentials.nil?
      url = authorizer.get_authorization_url(
          base_url: OOB_URI)
      puts "Open the following URL in the browser and enter the " +
               "resulting code after authorization"
      puts url
      code = gets
      credentials = authorizer.get_and_store_credentials_from_code(
          user_id: user_id, code: code, base_url: OOB_URI)
    end
    credentials
  end

创建方法:

def create_meeting
    # Initialize the API
    service = Google::Apis::CalendarV3::CalendarService.new
    service.client_options.application_name = APPLICATION_NAME
    service.authorization = authorize
    ...
    # Create event end post
    ...
  end

当我开始这个方法时,我必须做一些控制台技巧(我从谷歌获取一个令牌并将它们传递到控制台)并在事件发布之后。我可以自动化这个过程吗?还是拿寿命长的token?

此过程必须在没有用户的情况下运行。

【问题讨论】:

    标签: ruby-on-rails google-api google-calendar-api


    【解决方案1】:

    我找到了解决方案。需要使用服务器到服务器的身份验证。

    下一页有这个解决方案:Rails + Google Calendar API events not created

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2021-11-22
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      相关资源
      最近更新 更多