我正在尝试按照 documentation page 上的示例复制现有电子表格文档。 。我使用 ClientLogin
方法进行身份验证。我的第一步是获取模板文档:
SpreadsheetService service =
new SpreadsheetService("MySpreadsheetIntegration-v1");
service.setUserCredentials(USERNAME, PASSWORD);
DocumentQuery query = new DocumentQuery(new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full"));
query.setTitleQuery("template");
query.setTitleExact(true);
SpreadsheetFeed feed = service.getFeed(query, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
SpreadsheetEntry template = spreadsheets.get(0);
一切都很好。在 template
我有文档。然后我尝试创建一个新的:
SpreadsheetEntry newDoc = new SpreadsheetEntry();
newDoc.setTitle(new PlainTextConstruct("new copy"));
newDoc.setId(template.getId());
service.insert(new URL("https://docs.google.com/feeds/default/private/full"), newDoc);
我收到AuthenticationException: token 无效
。如果我使用 https://docs.google.com/feeds/default/private/full
检索文档,它就会失败。所以我猜 docs.google.com/...
需要某种更高的权限,但如何获得它们?
最佳答案
我猜您无法使用 ClientLogin
身份验证模型创建文档。使用 Oauth。
关于java - 制作谷歌电子表格的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11456357/