无法获取 Google Drive API v3 返回的 nextPageToken、incompleteSearch 和 files。

huangapple go评论72阅读模式
英文:

Cannot get Google Drive API v3 to return nextPageToken,incompleteSearch,files

问题

我知道从版本3开始,

GET https://www.googleapis.com/drive/v3/files

只返回一个包含名称、ID等信息的较小文档数组。如果我将它更改为:

GET https://www.googleapis.com/drive/v3/files?fields=files
或
GET https://www.googleapis.com/drive/v3/files?fields=files(id,name,createdTime,size)

它可以正常工作;我会得到大量详细信息。但是,我似乎无法找到正确的方法来获取一个单一文档,其中包括nextPageTokenincompleteSearch以及files数组。我希望

GET https://www.googleapis.com/drive/v3/files?fields=nextPageToken,files(id,name,createdTime,size)

会起作用,但实际上它不起作用。事实上,

GET https://www.googleapis.com/drive/v3/files?fields=nextPageToken

返回一个空数组(但是返回代码为200)。我真的希望能够得到:

{
   nextPageToken: ...
   incompleteSearch: ...
   files: [
      {id,name,createdTime,size},
      {id,name,createdTime,size}
   ]
}

这一切都通过requests进行,OAuth2令牌设置是正常的。

编辑
下面的解决方案在直接从curl命令行调用时按照描述的方式工作。但是,从使用requests的Python程序调用时则不起作用。
更多信息将会提供……

英文:

MAJOR EDIT
This entire post is the result of a pilot error. There was a python function within another function that was extracting only the files key from the returned response. This was completely missed. The program works fine. The answer below is correct.


I know that as of v3,

GET https://www.googleapis.com/drive/v3/files

returns only an array of much smaller docs with name, id, etc. If I change this to:

GET https://www.googleapis.com/drive/v3/files?fields=files
or
GET https://www.googleapis.com/drive/v3/files?fields=files(id,name,createdTime,size)

it works; I get back loads of detailed information. But I cannot seem to find the right incantation to get it to emit a single doc that includes nextPageToken and incompleteSearch along with the array of files. I was hoping

GET https://www.googleapis.com/drive/v3/files?fields=nextPageToken,files(id,name,createdTime,size)

would work but it does not. In fact,

GET https://www.googleapis.com/drive/v3/files?fields=nextPageToken

yields an empty array (but return code 200). I'd really like to get:

{
   nextPageToken: ...
   incompleteSearch: ...
   files: [
      {id,name,createdTime,size},
      {id,name,createdTime,size}
   ]
}

This is all going through requests and the OAuth2 bearer token setup is fine.

EDIT
The solution below works as described when called directly on the command line from curl. But from a python program using requests, it does not.
More to come on this….

答案1

得分: 3

在你的情况下,以下字段值如何?

incompleteSearch,nextPageToken,files(id,name,createdTime,size)

当这个反映在"Method: files.list"的终点时,它变成如下所示。在这种情况下,查询参数与URL编码一起使用。请注意这一点。

https://www.googleapis.com/drive/v3/files?fields=incompleteSearch%2CnextPageToken%2Cfiles(id%2Cname%2CcreatedTime%2Csize)

通过这个终点,返回以下结果。

{
  "nextPageToken": "###",
  "incompleteSearch": ###,
  "files": [
    {
      "size": "12345",
      "id": "###",
      "name": "###",
      "createdTime": "2023-01-01T00:00:00.000Z"
    },
    ,
    ,
    ,
  ]
}

参考资料:

英文:

In your situation, how about the following field value?

incompleteSearch,nextPageToken,files(id,name,createdTime,size)

When this is reflected in the endpoint of "Method: files.list", it becomes as follows. In this case, the query parameter is used with the URL encoding. Please be careful about this.

https://www.googleapis.com/drive/v3/files?fields=incompleteSearch%2CnextPageToken%2Cfiles(id%2Cname%2CcreatedTime%2Csize)
  • By this endpoint, the following result is returned.

    {
      "nextPageToken": "###",
      "incompleteSearch": ###,
      "files": [
        {
          "size": "12345",
          "id": "###",
          "name": "###",
          "createdTime": "2023-01-01T00:00:00.000Z"
        },
        ,
        ,
        ,
      ]
    }
    

References:

huangapple
  • 本文由 发表于 2023年6月2日 03:07:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384984.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定