GoogleJsonResponseException 403 禁止 PERMISSION_DENIED
GoogleJsonResponseException 403 Forbidden PERMISSION_DENIED
我正在使用 google REST Api 来检索电子表格列表。
当我的帐户访问它时,一切正常。
但是当我尝试使用国外账户时,出现了这个错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden {
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "The caller does not have permission",
"reason" : "forbidden"
} ],
"message" : "The caller does not have permission",
"status" : "PERMISSION_DENIED"
}
它说我无权访问我的 google 脚本,但该脚本已设置为对任何人可见和共享。
代码:
private Object getDataFromApi(ExecutionRequest request)
throws IOException
{
if (BuildConfig.DEBUG) {
request.setDevMode(true); // it will take saved version of script and not the published one
}
// Make the request.
Operation op =
mService.scripts().run(SCRIPT_ID, request).execute();
我发现问题出在代码中:
if (BuildConfig.DEBUG) {
request.setDevMode(true); // it will take saved version of script and not the published one
}
看起来它总是强制访问保存的版本而不是发布的版本。然后外国账户无法访问保存的版本并且returns错误403.
当我禁用此开发模式或安装发布版本时,一切正常。
将范围从 SheetsScopes.SPREADSHEETS_READONLY 更改为 SheetsScopes.SPREADSHEETS。
private static final List SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);
我正在使用 google REST Api 来检索电子表格列表。 当我的帐户访问它时,一切正常。
但是当我尝试使用国外账户时,出现了这个错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden {
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "The caller does not have permission",
"reason" : "forbidden"
} ],
"message" : "The caller does not have permission",
"status" : "PERMISSION_DENIED"
}
它说我无权访问我的 google 脚本,但该脚本已设置为对任何人可见和共享。
代码:
private Object getDataFromApi(ExecutionRequest request)
throws IOException
{
if (BuildConfig.DEBUG) {
request.setDevMode(true); // it will take saved version of script and not the published one
}
// Make the request.
Operation op =
mService.scripts().run(SCRIPT_ID, request).execute();
我发现问题出在代码中:
if (BuildConfig.DEBUG) {
request.setDevMode(true); // it will take saved version of script and not the published one
}
看起来它总是强制访问保存的版本而不是发布的版本。然后外国账户无法访问保存的版本并且returns错误403.
当我禁用此开发模式或安装发布版本时,一切正常。
将范围从 SheetsScopes.SPREADSHEETS_READONLY 更改为 SheetsScopes.SPREADSHEETS。
private static final List SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);