【问题标题】:Using Google Client Api how do i query for spreadsheets not in trash?使用 Google Client Api 如何查询不在垃圾箱中的电子表格?
【发布时间】:2013-05-30 19:08:37
【问题描述】:

无论 mimeType 和垃圾状态如何,我所有将 mimeType 传递并丢弃到客户端执行的尝试都失败或返回我的所有文档。

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 所需的电子表格密钥?从查询返回的文件资源没有任何电子表格关键信息。

【问题讨论】:

    标签: ruby google-drive-api google-api-client


    【解决方案1】:

    你能试试这个吗?

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

    实际上,如果您发送语法错误的查询,它将返回 400 Bad Request,而不是所有文件的 200 Success。可能是您实际上没有通过任何东西。

    【讨论】:

    • 谢谢。因此,我试图在我的句子尝试中过滤的项目周围的引号导致了问题。从该数据或谷歌驱动器获取电子表格密钥的任何线索?
    • 现在您已经获得了 Files.list() 的结果,每个文件或文件夹都会有一个属性“id”。那是电子表格键。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多