【发布时间】:2017-06-23 08:36:32
【问题描述】:
我想从已登录用户的 Google 表格电子表格中提取数据以进行某些处理。我在Google Console 中设置了一个应用程序:
- Google 云端硬盘 API
- 联系人 API
- Google+ API
- Google 表格 API
我还连接了devise/oauth,以便它可以成功登录。但是,每当我尝试使用在我的from_omniauth 方法中收到的access_token 时,我得到:
dailyLimitExceededUnreg: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.
我做错了什么?
我的代码(使用google-api-client)如下:
# frozen_string_literal: true
require 'google/apis/drive_v2'
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, omniauth_providers: [:google_oauth2]
has_many :datasets, inverse_of: :user
# Omniauth support
def self.from_omniauth(access_token)
#session = GoogleDrive::Session.new( access_token )
drive = Google::Apis::DriveV2::DriveService.new
files = drive.list_files(
fields: "nextPageToken, files(id, name)",
q: "mimeType = 'application/vnd.google-apps.spreadsheet' AND trashed != true",
)
data = access_token.info
user = User.where(email: data['email']).first
unless user
user = User.create(
email: data['email'],
password: Devise.friendly_token[0, 20]
)
end
user
end
end
为了记录,我也尝试使用google-drive gem 并遇到了相同的响应。
【问题讨论】:
标签: devise google-drive-api ruby-on-rails-5 omniauth google-sheets-api