简体   繁体   English

Google文档列表API PDF文件下载不起作用(Android)

[英]Google Docs List API PDF File Download is not working ( Android )

We are developing an Android Application to download files from Google Doc.We were able to list the files using Google Docs List APIs. 我们正在开发一个Android应用程序以从Google Doc下载文件。我们能够使用Google Docs List API列出文件。 Also we were able to download spreadsheet files from google docs. 此外,我们还能够从Google文档下载电子表格文件。 But when we tried to download pdf file from google docs it always returns with 401 error. 但是,当我们尝试从Google文档下载pdf文件时,它总是返回401错误。 This is the code snipped we are using to download the file. 这是我们用来下载文件的代码片段。

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());
}

This is the URL that i generate to download the file. 这是我生成的用于下载文件的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 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

Any guess, why we are not able to download PDF, but spreadsheet formats are working ? 任何猜测,为什么我们无法下载PDF,但电子表格格式却可以正常工作?

I think that you are not requesting the correct scopes when authorizing the token. 我认为您在授权令牌时没有要求正确的作用域。 The scopes for which you should request the token are: 您应该请求令牌的范围是:

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

You just made me realize that a bug was introduced into the Authorization section of our documentation, removing the docs.googleusercontent.com scope. 您刚刚使我意识到,我们的文档的“授权”部分引入了一个错误,从而删除了docs.googleusercontent.com范围。 I will add that back. 我会加回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM