如何获取googleapi-nodejs-client的正确参数

问题描述 投票:0回答:1

我正在使用Google's officially supported Node.js client library for accessing Google APIs.

但是我正在努力为api调用找到正确的参数。我最接近的参考是Google API Explorer,但我仍然不知道在nodejs api中必须使用哪些参数(以及它们的含义)。

因此,我唯一需要做的就是在互联网上搜索代码示例以及反复试验。有没有更好的方法?

google-api google-api-nodejs-client
1个回答
0
投票

请将此视为几种可能的答案之一。

就我而言,当我在脚本中使用Google API时,我总是使用以下流程。

示例情况:

我想用示例情况对此进行解释。作为示例情况,我使用the method of Files: list in Drive API从Google云端硬盘中的特定文件夹中检索文件列表。

流量:
  1. 访问Google APIs Explorer

  • Search Drive API v3。并转到Drive API v3的参考页。 Ref
  • 访问“文件:列表”。 Ref
  • 在这里,您可以看到使用“文件:列表”的参数。 Ref
  • 为了搜索文件,在这里使用q。在这种情况下,您可以看到指向“ Search for files”的链接。
    • 从“搜索文件”中,发现所需的搜索查询为'1234567' in parents
  • 这里,请使用“尝试此API”。

    • 请单击方形按钮。您可以在下图看到它。

      enter image description here

    • 这样,您可以看到打开的窗口,如下图所示。

    • enter image description here

    • 将“请求参数”的'###' in parents放入q###是文件夹ID。由此,卷曲样品也被改变。另外,您可以使用“尝试此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示例中,我实现了对脚本的请求。

    [此外,当我通过各种语言的googleapis使用对Google API的请求时,我会在每种googleapis的GitHub上检查脚本。例如,当我使用Node.js创建脚本时,我会按照您在问题中提到的那样检查googleapis中的Node.js。

    参考:

    © www.soinside.com 2019 - 2024. All rights reserved.