【问题标题】:How can I upload Document using React Native on Google Drive's Specific Folder?如何在 Google Drive 的特定文件夹上使用 React Native 上传文档?
【发布时间】:2020-04-23 16:55:50
【问题描述】:

我已经阅读了 Google Drive API 文档。但是我无法理解如何在 React Native 中实现文档上传器。 我已经获得了API key,但是有一个叫做YOUR_ACCESS_TOKEN 的东西在所有这些之间我被卡住了。 我可以提供一些参考,包括驱动 API 调用或 api_key 和 ACCESS_TOKEN 的代码/场景

 curl --request POST \
'https://www.googleapis.com/drive/v3/files?enforceSingleParent=true&ignoreDefaultVisibility=true&keepRevisionForever=true&supportsAllDrives=true&supportsTeamDrives=true&useContentAsIndexableText=true&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{}' \
--compressed

我收到了来自 Drive https://developers.google.com/drive/api/v3/reference/files/create 的 Try It 的 Curl 请求 提前致谢。

【问题讨论】:

    标签: javascript react-native google-drive-api


    【解决方案1】:

    access token 是 Google API 用于身份验证和授权的 OAuth 2.0 协议的一部分。正如here 所总结的,该过程如下:

    首先,从Google API Console 获取 OAuth 2.0 客户端凭据。然后,您的客户端应用程序从 Google 授权服务器请求访问令牌,从响应中提取令牌,并将令牌发送到您要访问的 Google API。

    在这里,您可以看到移动应用 OAuth 2.0 流程的完整指南,我猜您的情况是:OAuth 2.0 for Mobile & Desktop Apps。流程基本如下:

    1. Google Cloud console 中创建一个项目,为其启用 Drive API 并创建授权凭据。见Prerequisites
    2. 向 Google 的 OAuth 2.0 服务器发送请求以获取访问令牌,并获取刷新和访问令牌。见Obtaining OAuth 2.0 access tokens
    3. 使用访问令牌发出 API 请求。见Calling Google APIs

    注意:

    • 我建议您仔细阅读这两个参考页面。

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      相关资源
      最近更新 更多