我们正在开发一个 Android 应用程序来从 Google Doc 下载文件。我们能够使用 Google Docs List API 列出文件。我们还能够从谷歌文档下载电子表格文件。但是当我们尝试从 google docs 下载 pdf 文件时,它总是返回 401 错误。这是我们用来下载文件的代码 fragment 。
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(C.OAuth.CONSUMER_KEY, C.OAuth.CONSUMER_SECRET);
consumer.setMessageSigner(new HmacSha1MessageSigner());
consumer.setTokenWithSecret(token, secret);
.........
String url1 = consumer.sign(obj.url+"&exportFormat=txt"); // Create complete url
get.setURI(URI.create(url1));
response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
Log.v("GDATA MAIN", "not error");
}
else
{
Log.v("GDATA MAIN", "error"+response.getStatusLine().getStatusCode());
}
这是我生成的用于下载文件的 URL。
任何猜测,为什么我们无法下载 PDF,但电子表格格式可以?
最佳答案
我认为您在授权 token 时没有请求正确的范围。您应该请求 token 的范围是:
https://docs.google.com/feeds/
https://spreadsheets.google.com/feeds/
https://docs.googleusercontent.com/
您刚刚让我意识到我们文档的授权部分中引入了一个错误,删除了 docs.googleusercontent.com 范围。我会把它加回去。
关于java - Google Docs List API PDF 文件下载不工作 (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8534264/