本文介绍了使用Java通过API写入GoogleSheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用Google Sheet API和Java为单元格写入值。
对于阅读,我使用了的指导,该指导对我来说工作得很好。
写入Google表格我使用:
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:请求的认证范围不足。,
原因:禁止
}],
message:请求的认证范围不足。,
status:PERMISSION_DENIED
}
作为我使用的认证范围
private static final List< String> SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);
解决方案
显然有几个问题在一起:
- 删除存储在/Users/XXX/.credentials中的凭据。
- 将范围更改为SheetsScopes.SPREADSHEETS。
- Google表格共享和编辑选项位于工作表本身上。
谢谢你们的帮助I am trying to write a value to a cell with Google Sheet API with Java.For reading I used guide from Java Quickstart which worked fine for me.
For writing to Google Sheet I use:
service.spreadsheets().values().update(spreadsheetId, "Sheet1!A4:H", response).execute();
This function outputs the following error while run:
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" }
As a Authentication Scope I am using
private static final List<String> SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS);
解决方案Apparently there were several issues together:
- Delete credentials that were stored at /Users/XXX/.credentials.
- Change Scopes to SheetsScopes.SPREADSHEETS.
- Google Sheet Share and Edit options at on Sheet itself.
Now it works!Thank you guys for help
这篇关于使用Java通过API写入GoogleSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ b