2015-05-08 77 views
0

我試圖讓我的軌控制器設置爲下載從谷歌驅動器文件中的代碼以下驅動器 - https://developers.google.com/drive/v2/reference/files/get無法從谷歌下載文件與紅寶石

我有下面的Rails代碼

def download_file(client, file) 
    if file.download_url 
    result = client.execute(:uri => file.download_url) 
    if result.status == 200 
     return result.body 
    else 
     puts "An error occurred: #{result.data['error']['message']}" 
     return nil 
    end 
    end 
end 

def attachExternalResume 
    # read remote url to file 
    file_id = params[:fileId] 
    client = Google::APIClient.new 
    drive = client.discovered_api('drive', 'v2') 
    result = client.execute(
    :api_method => drive.files.get, 
    :parameters => { 'fileId' => file_id} 
) 
    if (result.status == 200) 
    p download_file client, result.data 
    end 
end 

這是從我的JavaScript前端使用谷歌選擇器調用。用戶通過谷歌選擇器授權我的應用程序,並選擇一個文件,導致我的角度JavaScript發佈文件ID到我的rails方法。在rails代碼中,我收到以下錯誤 - 缺少訪問令牌。

即使用戶已經在前端授權了應用程序,該授權似乎沒有通過導軌方式。任何人都知道如何在整個過程中獲得授權?

回答

0

「我收到以下錯誤 - 缺少訪問令牌。」可能意味着你錯過了一個訪問令牌。在您發佈的代碼片段中,我無法看到您請求訪問令牌的任何地方,因此更有可能。我對Google Ruby庫知之甚少,無法爲您提供缺失的代碼,但需要尋找作用域應用程序/客戶端ID作爲參數。