簡體   English   中英

如何在google-api-ruby-client中設置搜索參數

[英]how to set search parameter in google-api-ruby-client

為了檢索文件夾的內容,我必須使用以下URL https://www.googleapis.com/drive/v2/files?q='root ',所以我認為應該通過傳遞附加參數來使其正常工作

    @client.execute(
    :api_method => @drive.files.list ,
    :parameters =>{q=> "title='root'" })

但這不起作用

發生錯誤:{“錯誤” => [{“域” =>“全局”,“原因” =>“無效”,“消息” =>“無效值”,“ locationType” =>“參數”,“ location“ =>” q“}],”代碼“ => 400,”消息“ =>”無效值“}

當我看到請求uri時,這很明顯

https://www.googleapis.com/drive/v2/files?q=title%253D%27levelA%27

我的第一次嘗試是使用URI.encode“ title ='root'”,這兩個方法都不起作用。 我真的不知道如何保留單引號?

菲利普(Philip)

ps:指向上述寶石的鏈接http://rubydoc.info/github/google/google-api-ruby-client/frames

好的,現在我找到了一個可行的解決方案,盡管這是一個非常麻煩的解決方案。

search = CGI.escape("q='root'")
u.query = search
u= Addressable::URI.parse "https://www.googleapis.com/drive/v2/files"
req=Google::APIClient::Request.new(:uri=> u)
client.execute req

我希望這可以幫助別人..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM