Ruby on rails 在Ruby中打开并读取Google Drive中的文件

Ruby on rails 在Ruby中打开并读取Google Drive中的文件,ruby-on-rails,ruby,ruby-on-rails-4,google-api,rubygems,Ruby On Rails,Ruby,Ruby On Rails 4,Google Api,Rubygems,我正在使用GoogleDriveAPI,它为我提供了“导出链接”,这些链接似乎可以重定向以下载文档 结果表明: {"text/csv":"https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxxxxxx-rI&exportFormat=csv", "application/pdf":"https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A

我正在使用GoogleDriveAPI,它为我提供了“导出链接”,这些链接似乎可以重定向以下载文档

结果表明:

{"text/csv":"https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxxxxxx-rI&exportFormat=csv",
"application/pdf":"https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxxxxxx-rI&exportFormat=pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxxxxxx-rI&exportFormat=xlsx"}
我正在使用,但当我尝试读取其中一个文件时,我得到一个结果,表明“内容已移动”,因此会出现某种重定向


我如何打开这些URL中的一个,以便Yomu可以读取它们,或者您知道使用Google Drive API获得所需数据的其他方法吗?

我可以使用curl加载该文件,而且似乎工作正常。顺便说一句,如果您想保持文档的私密性,您需要在PDF和XLSX URL中屏蔽
id
。此外,CSV将比XLSX文件更易于使用

试试你的壳

curl "https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxx-rI&exportFormat=csv"
在IRB/rails控制台会话中尝试:

`curl "https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxx-rI&exportFormat=csv"`

require 'open-uri'
open('https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxx-rI&exportFormat=csv').read

require 'csv'
require 'open-uri'
CSV.parse(open('https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxx-rI&exportFormat=csv'))
如果您确实想使用完整的XLSX:

require 'yomu'
Yomu.new('https://docs.google.com/spreadsheets/export?id=1w6oq05R8piP4N4A-xxxx-rI&exportFormat=xlsx').text

但是结果看起来难以置信地难以解析。

我尝试使用的前几个文档似乎存在某种权限问题或特定于它们的某些条件,这导致了“移动”通知。我尝试了其他一些文件,并以我想要的方式成功地使用了Yomu