在的GData API会preadsheet认证 [英] Spreadsheet Authentication in GData API
本文介绍了在的GData API会preadsheet认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编辑使用的GData API一个gdocs US preadsheet。我有以下的code:
I'm trying to edit a gdocs spreadsheet using the GData API. I have the following code:
_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();
不过,在该块的最后一行,它抛出一个异常:
however, on the last line of that block, it throws an exception:
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)
...
用户名/密码是正确的,似乎验证精细查询我的文档,但是不久就因为我设法得到它失败的工作表。我缺少的是什么在这里的任何想法?
The username/password are correct, and seems to authenticate fine to query my documents, but soon as I try to get the worksheet it fails. Any ideas of what I'm missing here?
推荐答案
在一些试验和错误我发现供稿网址是不正确的。这是我不得不改变什么:
after some more trial and error I found that the feed URL was incorrect. Here's what I had to change:
修改
String feedUrl = "https://docs.google.com/feeds/default/private/full";
到
String feedUrl = "https://spreadsheets.google.com/feeds/spreadsheets/private/full";
和它的工作。
这篇关于在的GData API会preadsheet认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文