如何为 googleapi-nodejs-client 获取正确的参数
How to get the correct parameters for the googleapi-nodejs-client
我正在使用Google's officially supported Node.js client library for accessing Google APIs.
但我正在努力寻找 api 调用的正确参数。我最接近的参考是 Google API Explorer 但我仍然不知道我必须在 nodejs api 中使用什么参数(以及它们的含义)。
所以我唯一能做的就是在互联网上搜索代码示例并反复试验。有没有更好的办法?
就我而言,当我在脚本中使用 Google API 时,我总是使用以下流程。
示例情况:
我想用一个示例情况来解释这一点。作为示例情况,我使用 the method of Files: list in Drive API.
从 Google 驱动器中的特定文件夹检索文件列表
流量:
- 访问Google APIs Explorer。
- 搜索驱动器 API v3。并转到 Drive API v3 的参考页面。 Ref
- 访问"Files: list"。 Ref
- 在这里,您可以看到使用"Files: list"的参数。 Ref
- 为了搜索文件,这里使用了
q
。在这种情况下,您可以看到 link 到“Search for files”。
- 从"Search for files",发现需要的搜索查询是
'1234567' in parents
。
这里使用"Try this API".
请单击方形按钮。您可以在下图中看到它。
这样就可以看到打开的window如下图
将 '###' in parents
放入 "Request parameters" 的 q
。 ###
是文件夹 ID。由此,卷曲样本也发生了变化。此外,您可以使用 "Try this API".
测试 API
curl \
'https://www.googleapis.com/drive/v3/files?q=%27###%27%20in%20parents&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
如果要确认Javascript样本,也可以看如下
function execute() {
return gapi.client.drive.files.list({
"q": "'###' in parents"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) {
console.error("Execute error", err);
});
}
在我的例子中,我从 curl 示例中实现了对脚本的请求。
此外,当我将请求 Google API 与每种语言一起使用 googleapis 时,我检查了每个 googleapis 的 GitHub 处的脚本。例如,当我使用 Node.js 创建脚本时,我会检查 googleapis 是否有你在问题中提到的 Node.js。
参考:
我正在使用Google's officially supported Node.js client library for accessing Google APIs.
但我正在努力寻找 api 调用的正确参数。我最接近的参考是 Google API Explorer 但我仍然不知道我必须在 nodejs api 中使用什么参数(以及它们的含义)。
所以我唯一能做的就是在互联网上搜索代码示例并反复试验。有没有更好的办法?
就我而言,当我在脚本中使用 Google API 时,我总是使用以下流程。
示例情况:
我想用一个示例情况来解释这一点。作为示例情况,我使用 the method of Files: list in Drive API.
从 Google 驱动器中的特定文件夹检索文件列表流量:
- 访问Google APIs Explorer。
- 搜索驱动器 API v3。并转到 Drive API v3 的参考页面。 Ref
- 访问"Files: list"。 Ref
- 在这里,您可以看到使用"Files: list"的参数。 Ref
- 为了搜索文件,这里使用了
q
。在这种情况下,您可以看到 link 到“Search for files”。- 从"Search for files",发现需要的搜索查询是
'1234567' in parents
。
- 从"Search for files",发现需要的搜索查询是
这里使用"Try this API".
请单击方形按钮。您可以在下图中看到它。
这样就可以看到打开的window如下图
将
测试 API'###' in parents
放入 "Request parameters" 的q
。###
是文件夹 ID。由此,卷曲样本也发生了变化。此外,您可以使用 "Try this API".curl \ 'https://www.googleapis.com/drive/v3/files?q=%27###%27%20in%20parents&key=[YOUR_API_KEY]' \ --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \ --header 'Accept: application/json' \ --compressed
如果要确认Javascript样本,也可以看如下
function execute() { return gapi.client.drive.files.list({ "q": "'###' in parents" }) .then(function(response) { // Handle the results here (response.result has the parsed body). console.log("Response", response); }, function(err) { console.error("Execute error", err); }); }
在我的例子中,我从 curl 示例中实现了对脚本的请求。
此外,当我将请求 Google API 与每种语言一起使用 googleapis 时,我检查了每个 googleapis 的 GitHub 处的脚本。例如,当我使用 Node.js 创建脚本时,我会检查 googleapis 是否有你在问题中提到的 Node.js。