在 Google Drive Picker 中使用搜索栏显示无结果并在网络响应中抛出内部错误

Using search bar in Google Drive Picker shows no results and throws internal error in network response

我在应用程序中实现了 Google 选择器 API,其中包含 Google 驱动器视图。目前,在 Google 驱动器视图的搜索栏中输入搜索查询会开始显示一个包含一些文件结果的下拉列表,如下所示:

search bar drop down

但是,单击 "magnifying glass" 搜索按钮,或按回车键,或单击 "search for all items containing...",所有结果都是一个空的选择器,如下所示:

empty picker with no search results

我相信这是因为每次调用 https://docs.google.com/picker/pvr 都会返回此错误作为响应:&&&START&&&{"error":true,"errorMessage":"Internal error"}.

发送到 /pvr 端点的参数在这里:

start: 0
numResults: 50
sort: 3
desc: true
q: testing
cursor: 
mine: 2
service: docs
type: NOT_COLLECTION
options: {"ff":true,"filterTeamDriveResults":true}
token: J********
version: 4
app: 2
clientUser: 1************
developerKey: A*************
subapp: 5

我发现从 "options" 哈希中手动删除 "filterTeamDriveResults":true 密钥并执行 ajax post 直接导致请求成功,但无论选择器的每个请求都包含该选项的原因,并且每当包含该选项的请求发出时,它似乎都会因相同的 "Internal error" 响应而失败。我想知道该选项的来源是什么,以及是否有任何方法可以将其从我们的选择器中删除。据我所知,它似乎不受我们从 https://apis.google.com/js/api.js?onload=onApiLoad.

加载的 JavaScript API 中的任何选项控制

在我们使用 Google 选择器 API 多年没有出现任何问题后,上周也开始出现这种情况。你关于 filterTeamDriveResults 键的线索让我想起了我刚刚读到的关于 upcoming changes to the Google Drive API and Google Picker API:

的内容

Next, we’re introducing a new Drive API resource collection, called “Drives,” to replace the “Team Drives” resource collection. This new resource collection can help you create, delete, get, list and update your shared drives, and features all the same fields, resources and available methods as the “Team Drives” resource collection. If you have been using the “Team Drives” resource collection in your applications, consider migrating as soon as possible as all related fields for Drive API , Drive Activity API and Google Picker API, will no longer be supported starting June 1, 2020.

它似乎不相关,至少不直接相关,但让我想到也许我在文档中看到的 the SUPPORT_DRIVES feature 可能 "disable" 其他 teamDrive 功能(虽然不是真的,但仍然......)。事实上,这解决了它。基本上只是:

new google.picker.PickerBuilder().
  setAppId(appId).
  addView(new google.picker.DocsView().setIncludeFolders(true)).
  enableFeature(google.picker.Feature.SUPPORT_DRIVES)
...

需要注意的一件事是启用此功能时出现此警告:

Before enabling this make sure to refer to Google Drive API documentation for enabling shared drives and make any necessary Drive Rest API changes.

可能与您的情况相关。