繁体   English   中英

从网络应用程序访问 Google 驱动器中的文件和文件夹

[英]Access file and folder from Google drive from web application

我正在尝试创建一个 ASP.NET MVC Web 应用程序来访问 Google 驱动器文件。

到目前为止我创建的内容:

  1. 从 Google 开发者控制台启用我的 API。
  2. 为提供“OAuth 2.0 客户端 ID”的 Web 应用程序创建了一个项目及其凭据。
  3. 我已将其粘贴到我的 Web 应用程序中。

如果我创建一个控制台应用程序,它可以正常工作,但不能在 Web 应用程序中运行。 我收到身份验证错误。

我已经点击了这个链接,但如果你详细查看,你会发现它有 client_secret.json,它只适用于已安装的应用程序(桌面应用程序)。

身份验证错误就像这个附加的截图

回答

根据.NETGoogle Drive API 文档, 400 错误是由于在这种情况下缺少参数redirect_uri 您必须确保您的credentials.json具有以下格式:

{
  "installed": {
    "client_id": "xxxx.apps.googleusercontent.com",
    "project_id": "quickstart-xxxx",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "xxxx",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "https://example.com"
    ],
    "javascript_origins": [
      "https://example.com"
    ]
  }
}

其中"urn:ietf:wg:oauth:2.0:oob"是您告诉 OAuth 服务器您希望代码在同一页面中的方式。 我强烈建议您搜索官方 Google 文档。 有关访问 Google API 的更多信息,请查看Google OAuth 文档

参考

Google Drive API 文档

用于访问 Google API 的 OAuth 2.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM