【发布时间】:2016-09-27 23:53:16
【问题描述】:
我正在尝试使用带有 Java 的 Google Sheet API 将值写入单元格。 为了阅读,我使用了来自Java Quickstart 的指南,这对我来说效果很好。
为了写到谷歌表格,我使用:
service.spreadsheets().values().update(spreadsheetId, "Sheet1!A4:H", response).execute();
此函数在运行时输出以下错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Request had insufficient authentication scopes.",
"reason" : "forbidden"
} ],
"message" : "Request had insufficient authentication scopes.",
"status" : "PERMISSION_DENIED"
}
作为我正在使用的身份验证范围
private static final List<String> SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);
【问题讨论】:
-
您检查过您的
client-secret.json文件吗?或者在授权电子表格请求时使用正确的scopes。我希望这会有所帮助。 -
在构建身份验证流程时尝试使用approval_prompt=false。
-
@Mr.Rebot 我重新创建了 client-secret.json 但没有任何改变。关于范围 - 我是否使用了原始消息中所述的正确范围?
-
@hoozecn 你能解释一下流程吗?
-
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(DATA_STORE_FACTORY) .setAccessType("offline").setApprovalPrompt("force") .build();
标签: java google-api google-api-java-client google-sheets-api