2015-10-20 154 views
1

我正在使用Google驱动器API,它为我提供了“导出链接”,这些链接似乎是为了下载文档而重定向的。在Ruby中打开并从Google云端硬盘读取文件

结果提供了这一点:

{"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"} 

我使用Yomu但是当我尝试读取这些文件之一,我得到一个结果,指出“的内容已移至”,所以各种各样的重定向。

如何打开这些URL中的一个以便Yomu可以阅读这些URL?或者您是否知道使用Google Drive API实现所需数据的其他方法?

回答

0

我能够使用curl加载该文件,它似乎工作正常。顺便说一句,如果你想保持文档的私密性,你需要在PDF和XLSX URL中掩盖id。此外,CSV将比XLSX文件更易于使用。

尝试在你的shell

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

尝试在IRB /导轨控制台会话:

`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 

但结果看起来难以解析。

0

看起来好像我试图使用的前几个文档有某种权限问题或某些特定于他们的标准导致“移动”通知。我尝试了其他一些文件,并以我想要的方式成功使用Yomu。

相关问题