gpt4 book ai didi

java - GData API 中的电子表格身份验证

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:59 25 4
gpt4 key购买 nike

我正在尝试使用 GData API 编辑 gdocs 电子表格。我有以下代码:

    _service = new DocsService("attask-gdocsintegration-1.0");
_service.setUserCredentials(username, password);

String feedUrl = "https://docs.google.com/feeds/default/private/full";

SpreadsheetQuery query = new SpreadsheetQuery(new URL(feedUrl));
query.setMaxResults(1);
query.setTitleExact(true);
query.setTitleQuery(title);
SpreadsheetFeed feed = _service.getFeed(query, SpreadsheetFeed.class);

if(feed.getEntries().size() != 1) {
throw new FileNotFoundException("'"+title+"' not a spreadsheet");
}
_entry = feed.getEntries().get(0);
List<WorksheetEntry> worksheets = _entry.getWorksheets();

但是,在该 block 的最后一行,它抛出异常:

Exception in thread "main" com.google.gdata.util.AuthenticationException: Unauthorized
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
...

用户名/密码是正确的,并且似乎可以很好地验证查询我的文档,但当我尝试获取工作表时,它失败了。关于我在这里缺少什么的任何想法吗?

最佳答案

经过多次尝试和错误后,我发现提要 URL 不正确。这是我必须更改的内容:

更改:

String feedUrl = "https://docs.google.com/feeds/default/private/full";

至:

String feedUrl = "https://spreadsheets.google.com/feeds/spreadsheets/private/full";

并且成功了。

关于java - GData API 中的电子表格身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4726209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com