我想使用服务帐户通过Apps脚本执行API访问Google表格,但是文档中是否支持这一点并不清楚.
我尝试过的步骤(导致Execution API的403状态)是:
这是我得到的回应:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为服务帐户永远无法访问Execution API吗?或者上面的步骤有问题吗?
我在脚本编辑器中创建了一个脚本,将其发布为"Deploy as API executable".在这个脚本中,我向我的工作表提供了一个doc_id,并定义了一个从该工作表中获取数据的函数.
然后我转到https://developers.google.com/apps-script/execution/rest/v1/scripts/run来测试执行API.我添加了范围,授权应用程序并尝试了它.我收到以下错误消息:
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我做错了什么吗?
我每隔1.5分钟就用我的C#app执行一次Google应用程序脚本.应用脚本在电子表格和编辑表单之间移动内容.我也使用Drive API.
我的脚本长时间运行良好,除了我每小时收到5分钟的授权错误.
这是我处理授权的代码:
class Authentication
{
public static ScriptService ScriptsAuthenticateOauth(UserCredential credential)
{
try
{
ScriptService service = new ScriptService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp",
});
return service;
}
catch (Exception ex)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm") + ": An authentication error occurred: " + ex.InnerException);
return null;
}
}
public static UserCredential getCredential(string clientId, string clientSecret, string userName)
{
string[] scopes = new string[] { DriveService.Scope.Drive, // view and manage your files and documents
DriveService.Scope.DriveAppdata, // view and manage …Run Code Online (Sandbox Code Playgroud)