Google Drive API-使用API​​密钥请求文件列表时出现权限错误403-C#

我一直在搜寻互联网以寻求解决方案。我的C#应用​​程序使用的是Google Drive API。我有一个用于身份验证的API密钥。由于该项目用于远程客户端,因此我选择不使用Oauth 2.0凭据。似乎API密钥允许我连接到google项目,但是尝试执行列表请求时出现权限错误:(用户对此文件没有足够的权限。[403])。

所有文件/文件夹均已设置为公共,API密钥设置为无限制,并且启用了Drive API。任何帮助,将不胜感激。 [1]:https://i.stack.imgur.com/OJemM.jpg还包括显示错误输出的图像链接。

 private static void DriveTest(string clientVersionFile,string clientBuildFile) {

        // Create Drive API service.
        var service = new DriveService(new BaseclientService.Initializer() {
            ApiKey = apiKey,ApplicationName = appName,});

        // Define parameters of request.
        FilesResource.ListRequest listRequest = service.Files.List();
        listRequest.PageSize = 10;
        listRequest.Fields = "nextPageToken,files(id,name)";

        // ---- ERROR 403 ON THIS EXECUTE CALL   ------
        IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;

        // Loop through files and check for the requested file name. Once found,copy it's ID and break the loop.
        if (files != null && files.Count > 0) {
            foreach (var file in files) {
                if(file.Name == clientVersionFile) {
                    downloadID = file.Id;
                    foundFile = true;

                    Console.WriteLine("Got the requested file");
                    break;
                  }
              }
         }
    }
hewei600 回答:Google Drive API-使用API​​密钥请求文件列表时出现权限错误403-C#

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3116121.html

大家都在问