2015-10-20 152 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。

相關問題