1

我们正在开发一个 Android 应用程序来从 Google Doc 下载文件。我们能够使用 Google Docs List API 列出文件。我们还能够从谷歌文档下载电子表格文件。但是当我们尝试从谷歌文档下载 pdf 文件时,它总是返回 401 错误。这是我们用来下载文件的代码。

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。

https://doc-04-0s-docs.googleusercontent.com/docs/securesc/5pv2dhsk6q500b1vl99u2gr2gvpqfifr/d8oihkmccnh39ie9io5bhqaf3jof7t16/1324030500000/01234800628230479895/01234800628230479895/0B4royw-5u0TDNGU3ZjZiZTAtN2ZhNi00YWE3LWEwZGEtMTMwNWJhMGE1YWRk?h=16653014193614665626&e=download&gd=true&exportFormat=txt&oauth_signature=3lfP0reuJhMWstxMKMAlJh%2BZ7Ug%3D&oauth_token= 1%2FQnEPtLXrhT8q6yk8oLoI2ZPyZzQptbB4mQrBJf-HJfM&oauth_consumer_key=418002400742-nrh3mt73pfvl6flshi8f7uvki49ofqj8.apps.googleusercontent.com&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1324031523&oauth_nonce=351034367494689817

任何猜测,为什么我们不能下载 PDF,但电子表格格式可以工作?

4

1 回答 1

1

我认为您在授权令牌时没有请求正确的范围。您应该请求令牌的范围是:

https://docs.google.com/feeds/
https://spreadsheets.google.com/feeds/
https://docs.googleusercontent.com/

您刚刚让我意识到我们文档的授权部分引入了一个错误,删除了 docs.googleusercontent.com 范围。我会把它加回来。

于 2011-12-17T09:37:15.137 回答