1
votes

We are developing an Android Application to download files from Google Doc.We were able to list the files using Google Docs List APIs. Also we were able to download spreadsheet files from google docs. But when we tried to download pdf file from google docs it always returns with 401 error. 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.

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 ?

1
Your code snippet still does not show where you're setting your scopes. - Vic Fryzel
You can't export PDFs as text. Even with the exportFormat=txt, you'll still get PDF content. As for your error, you probably are missing the "Docs" or "PDF/File download" scopes in your OAuth token; these are distinct from the "Spreadsheet" scope required to access spreadsheets. - technomage

1 Answers

1
votes

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. I will add that back.