[英]How to download file from google drive using paperclip-googledrive?
[英]How to download a file via the Google Drive API?
我正在使用 gem google-api-client 通過 Google Drive API 下載文件。
x = Google::Apis::DriveV2
drive = x::DriveService.new
drive.authorization = auth
files = drive.list_files
files.items.each_with_index do |file, index|
url_to_index = file.export_links.select { |k, v| v if k == 'text/plain' }
file_content = open(url_to_index["text/plain"]).read
end
問題是 file_content 返回的是 Google 登錄屏幕,而不是文本/純格式的文件。 當我的 Rails 應用程序打開 URL 時,它似乎無權訪問文本文件。
讓我的 Rails 應用程序以文本格式獲取文件的正確方法是什么?
查看日志輸出:您需要通過兩個因素身份驗證才能允許從您的應用程序訪問您的 Google Drive 帳戶。
在日志中,您將看到執行此操作所需的信息:link 和 secret_key。
tail -f log/*.log
我只是意識到用於下載的 mimetype 與文件元不同。 請檢查此網址以獲取可用的 mimetype: https : //developers.google.com/drive/api/v3/integrate-open
例如 mimeType : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.