【问题标题】:Spreadsheet Authentication in GData APIGData API 中的电子表格身份验证
【发布时间】:2011-06-11 04:54:34
【问题描述】:

我正在尝试使用 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();

但是,在该块的最后一行,它会引发异常:

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)
    ...

用户名/密码是正确的,并且似乎可以通过身份验证来查询我的文档,但是一旦我尝试获取工作表,它就会失败。关于我在这里缺少什么的任何想法?

【问题讨论】:

  • 您好,您添加了哪个 gdata 库?我添加了 gdata-spreadsheet-3.0,因为我无法获取 SpreadsheetService 类的 setUserCredentials 方法。

标签: java authentication spreadsheet gdata-api


【解决方案1】:

经过反复试验,我发现提要 URL 不正确。这是我必须改变的:

改变了:

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

到:

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

它成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2017-10-18
    相关资源
    最近更新 更多