1

当我使用调试控制台执行 C#/.NET 代码以创建新项目 ( ProjectResource.Create(...)) 时,我收到“403 Forbidden”错误。但是,我仍然收到Project响应,并且 API 正确地在我的云端硬盘中创建了一个文件。因为 Google 没有公开他们的 API 下发生的事情,所以我不知道为什么我会在调试控制台中看到该消息。没有错误传播到运行时,我有一种奇怪的感觉,这是生产留下的错误输出错误消息。

为什么会发生这种情况,我可以删除/防止此错误吗?


代码:

var cpr = new CreateProjectRequest
{
     Title = name
};
scriptID = projectResource.Create(cpr).Execute().ScriptId;

错误:

调用者没有权限

错误对象:

Google.Apis.Requests.RequestError
The caller does not have permission [403]
Errors [
    Message[The caller does not have permission] Location[ - ] Reason[forbidden] Domain[global]
]

另一种可能性可能是我设置 Google Console Cloud 的方式存在问题,但考虑到功能仍然完好无损,我不禁认为我做得对。此外,我的凭据授权都成功且没有错误。

我通过以下方式授权我的服务:

 scriptService = new ScriptService(new BaseClientService.Initializer()
    {
         ApiKey = apiKeyUser,
         HttpClientInitializer = credential,
         ApplicationName = applicationName
    });
 projectResource = new ProjectsResource(scriptService);

我的 API 密钥设置为与 Apps Script API 和 Drive API 一起使用。我的 OAuth 客户端 ID 是type: other(这是桌面应用程序的唯一方式)。

有什么想法吗?

PS 在我的努力中,我尝试使用DriveService来做同样的事情。我仍然在调试中收到相同的错误,唉,它仍然像上面一样工作。

File body = new File()
{
    MimeType = "google-apps.script",
    Name = name,
};

var test = driveService.Files.Create(body);

test.Fields = "id";
var f = test.Execute();
4

0 回答 0