2017-08-28 127 views
1

我正在構建一個使用谷歌驅動器與服務帳戶的api。谷歌驅動器對象與服務帳戶的下載鏈接

谷歌驅動對象都配備了@web_view_link屬性,它看起來像:

"https://drive.google.com/file/d/0B9eyEerjltIgZ2dyUTB1eGNjYUk/view?usp=drivesdk"

當我在使用個人賬戶瀏覽器訪問該@web_view_link,鏈接功能和對象可下載從那裏。

當我粘貼@web_view_link在使用服務帳戶瀏覽器,谷歌驅動器抱怨權限和我不能訪問它,甚至儘管我與帳戶所有者訪問。

是否可以使用服務帳戶從谷歌驅動器訪問下載鏈接?

我使用google-drive-ruby寶石,這是檢索@web_view_link URL代碼:

def create_url 
    folder_name = Discourse.current_hostname 
    found = google_files.select { |f| f.id == id } 
    file_title = found.first.title 
    file_url = session.collection_by_title(folder_name).file_by_title(file_title).human_url 
end 

回答

1

服務帳戶是不是你的個人賬戶。服務賬戶belong to your application。確保您在生成服務帳戶並將角色設置爲所有者或編輯器時啓用了Drive API。

這從SO post片段也可能就有助於在使用紅寶石服務帳戶下載:

require 'googleauth' 
    require 'google/apis/drive_v2' 

    Drive = Google::Apis::DriveV2 

    upload_source = "/User/my_user_name/hacking.txt" 
    drive = Drive::DriveService.new 
    # Drive::AUTH_DRIVE is equal to https://www.googleapis.com/auth/drive 
    drive.authorization = Google::Auth.get_application_default([Drive::AUTH_DRIVE]) 
    file = drive.insert_file({title: 'hacking.txt'}, upload_source: upload_source) 
    drive.get_file(file.id, download_dest: '/tmp/my_file.txt') 
+1

我的問題是更多:您可以訪問與服務帳戶創建的對象的@web_view_link?這澄清..不:)。首先下載到服務器併發送*這個*鏈接給用戶將完成工作。 – catch22

相關問題