【问题标题】:Google drive API v3 - Keeps getting permission errorGoogle drive API v3 - 不断获得权限错误
【发布时间】:2016-12-09 08:11:13
【问题描述】:

我不确定我错过了什么,但我在安装 nuget 包后生成了“json”文件并将其连接到代码。我有权从谷歌驱动器文件夹中读取文件,但我无法创建文件。它一直给我一个权限错误。

var fileMetadata = new Google.Apis.Drive.v3.Data.File();
fileMetadata.Name = "SomeFile.txt";
fileMetadata.MimeType = "application/vnd.google-apps.drive-sdk";
var request = service.Files.Create(fileMetadata);
request.Fields = "id";
var file = request.Execute();

我已尝试将范围更改为 .Drive 和其他所有内容,但仍然无法正常工作。我该怎么办?是否应该是我在安装 API 的 nuget 包之前生成 json 的站点中遗漏的东西?

错误: Google.Apis.dll 但未在用户代码中处理

附加信息:Google.Apis.Requests.RequestError

权限不足 [403]

错误 [

Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]

谢谢

【问题讨论】:

    标签: c# permissions google-drive-api


    【解决方案1】:

    根据 Drive API 的文档,此 403 error 的建议操作是向用户报告需要请求这些权限才能更新文件。您可能还想检查files.get 检索到的元数据中的用户访问级别,并使用它来将您的 UI 更改为只读 UI。还要确保您按照Authorization 中的步骤操作。

    {
      "error": {
        "errors": [
          {
            "domain": "global",
            "reason": "insufficientFilePermissions",
            "message": "The user does not have sufficient permissions for file {fileId}."
          }
        ],
        "code": 403,
        "message": "The user does not have sufficient permissions for file {fileId}."
      }
    }
    

    Files:create 也需要这个范围:

    https://www.googleapis.com/auth/drive.file
    https://www.googleapis.com/auth/drive.appdata
    

    有关更多信息,请查看此相关 SO 问题,它可能会让您了解如何解决此问题。

    【讨论】:

      【解决方案2】:

      编辑:问题解决了。如果无论范围内的所有更改如何都发生在您身上,则可能出于任何原因从应该显示的对话框中被拒绝,并且您应该在浏览器中选择“允许”。例如,我从另一台计算机上尝试,它在调试时为我加载了浏览器(它只执行一次),并要求允许访问。之后,一切正常。对于当前拒绝访问的计算机,请在浏览器中打开驱动器并删除 API 正在使用的应用程序,然后它会再次为您提供对话框。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-10
        • 2016-09-02
        • 1970-01-01
        相关资源
        最近更新 更多