2013-05-30 52 views
2

我所有的傳遞mimeType並被拋到客戶端執行的嘗試都是失敗或返回所有文檔,而不管mimeType和垃圾的狀態如何。使用Google Client Api如何查詢電子表格不是垃圾?

require 'google/api_client' 
require 'launchy' 
load 'auth.rb' 

def client 
    @client 
end 

def drive 
    @drive 
end 

def session 
    unless client 
    @client = Google::APIClient.new 
    @drive = client.discovered_api('drive', 'v2') 
    client.authorization.client_id = client_id 
    client.authorization.client_secret = secret 
    client.authorization.scope = 'https://www.googleapis.com/auth/drive' 
    client.authorization.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' 

    uri = client.authorization.authorization_uri 
    Launchy.open(uri) 
    $stdout.write "Enter authorization code: " 
    client.authorization.code = gets.chomp 
    client.authorization.fetch_access_token! 
    end 
    client 
end 

#application/vnd.google-apps.spreadsheet 
def list_files 
    session 
    files = [] 
    #no matter how i go about trying to filter i always get all my docs... 
    params = "'mimeType' = 'application/vnd.google-apps.spreadsheet' and 'trashed' = false" 
    params = {'query' => {'mimeType' => 'application/vnd.google-apps.spreadsheet', 'trashed' => false}} 
    params = {'q' => {'mimeType' => 'application/vnd.google-apps.spreadsheet', 'trashed' => false}} 
    params = {'q' => "'mimeType' = 'application/vnd.google-apps.spreadsheet' and 'trashed' = false"} 
    params = {'mimeType' => 'application/vnd.google-apps.spreadsheet', 'trashed' => false} 
    begin 
    rsp = client.execute :api_method => drive.files.list, :parameters => params 
    #rsp = client.execute :api_method => drive.files.list, :q => params # have tried comin 
    files += rsp.data.items 
    puts "Token was #{params['pageToken']} but now #{rsp.next_page_token}" 
    params['pageToken'] = rsp.next_page_token unless rsp.next_page_token.nil? 
    end while !rsp.next_page_token.nil? 
    files 
end 

另外我怎樣才能使用谷歌驅動器結果來獲得使用電子表格api所需的電子表格鍵?查詢返回的文件資源沒有任何電子表格關鍵信息。

回答

4

你可以試試嗎?

params = {'q' => "trashed=false and mimeType='application/vnd.google-apps.spreadsheet'"} 

其實,如果你用錯誤的語法發送查詢時,它會返回400錯誤的請求,而不是200個成功的所有文件。可能是你實際上沒有傳遞任何東西。

+0

謝謝。所以,我試圖在我的句子中試圖過濾的項目引號引起了問題。從數據或谷歌驅動器獲取電子表格密鑰的任何線索? – Justin

+0

現在您已經從Files.list()獲得結果,每個文件或文件夾都會有一個屬性「id」。這是電子表格的關鍵。 –

相關問題