Java 制作谷歌电子表格的副本

Java 制作谷歌电子表格的副本,java,google-docs,google-docs-api,google-sheets,Java,Google Docs,Google Docs Api,Google Sheets,我正试图通过下面的示例复制现有的电子表格文档。我使用ClientLogin方法进行身份验证。我的第一步是获取模板文档: SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1"); service.setUserCredentials(USERNAME, PASSWORD); DocumentQuery query = new DocumentQuery(new URL(

我正试图通过下面的示例复制现有的电子表格文档。我使用
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);

我获得
身份验证异常:令牌无效
。如果我使用
https://docs.google.com/feeds/default/private/full
要检索文档,它就在那里失败了。所以我想
docs.google.com/…
需要某种更高的权限,但如何获得它们呢?

我想你不能用
ClientLogin
身份验证模型创建文档。使用Oauth。

@isola009不,还没有。我总是犯这个错误。现在我正在尝试OAuth。好的,如果您修复了它,请告诉我。我也将尝试使用OAuth2。@isola009使用OAuth1.0a和作用域
https://spreadsheets.google.com/feeds https://docs.google.com/feeds
我使用上述代码复制电子表格文档。
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);