Google drive api Rails Google Drive API(DriveV3)-服务帐户-示例?

Google drive api Rails Google Drive API(DriveV3)-服务帐户-示例?,google-drive-api,Google Drive Api,有没有人有一个小的工作示例,说明我如何让rails与GoogleDriveAPI(DriveV3)一起工作。 我真的很挣扎 我尝试过以下代码: myauth = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: StringIO.new(File.read('config/autoakey.json')), scope: ['https://www.googleapis.com/auth/drive'] )

有没有人有一个小的工作示例,说明我如何让rails与GoogleDriveAPI(DriveV3)一起工作。 我真的很挣扎

我尝试过以下代码:

myauth = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: StringIO.new(File.read('config/autoakey.json')),
  scope: ['https://www.googleapis.com/auth/drive']
)
gsess = Google::Apis::DriveV3::DriveService.new
gsess.client_options.application_name = 'rails2'
gsess.authorization = myauth
gsess.authorization.fetch_access_token!

@google_docs = []

page_token = nil
begin
  (myfiles, page_token) = gsess.list_files(page_size: 10, q: "name contains ' '", fields: 'files(id, name), nextPageToken')
  myfiles.files.each do |file|
    @google_docs << file.name
  end
end while page_token
myauth=Google::Auth::ServiceAccountCredentials.make\u creds(
json\u key\u io:StringIO.new(File.read('config/autoakey.json'),
范围:['https://www.googleapis.com/auth/drive']
)
gsess=Google::api::DriveV3::DriveService.new
gsess.client\u options.application\u name='rails2'
gsess.authorization=myauth
gsess.authorization.fetch\u access\u令牌!
@谷歌文档=[]
页面\标记=nil
开始
(myfiles,page_token)=gsess.list_文件(page_大小:10,q:“名称包含“””,字段:“文件(id,名称),nextPageToken”)
myfiles.files.each do|文件|

@google_docs事实证明,我读了很多关于“console.google.xxx”网站的文章,你需要记住将服务帐户添加到admin.google.com安全页面(在安全-转到API clientaccess管理下)。我做了这个。。。但这是我修复一切的线索:即使我可以访问这个域名。我仍然需要将服务帐户电子邮件添加到我想要查看的文件夹的“共享”菜单中:xxxxxxxautomations.iam.gserviceaccount.com。。。当我加上这个。。。突然,我的列表文件开始按预期返回文件。愚蠢的我…;-)嗨,索伦,我正面临着和你一样的问题。你把上面的代码贴在哪里了?你是怎么称呼它的?此外,您是否有一个将hello world ruby on rails应用程序与google drive集成的代码示例?我正在准备一个大型发行版。。。我记不起这个问题(解决方案)。。。但是我看了我的档案。。。也许这个文件可以帮助你:它仍然适用于我;-)。。。非常好,谢谢你-还有另外一个类控制器是指:GoogleDrive::GoogleDocs.new-你也可以粘贴它吗?我怀疑它有助于创建/管理服务。-也许它在/lib文件夹中,我不知道。如果是这样,那将是一个巨大的帮助:)chrsrehne.dk/posts/gdrivegdocs.rb