1

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 ?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Anwer
  • 689
  • 1
  • 7
  • 10
  • Your code snippet still does not show where you're setting your scopes. – Vic Fryzel Apr 07 '12 at 04:26
  • 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 Jul 05 '12 at 13:15

1 Answers1

1

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.

Vic Fryzel
  • 2,395
  • 16
  • 20
  • I am already using same scope, this is my scope and request url final protected static String SCOPE = "https://docs.google.com/feeds/ https://spreadsheets.google.com/feeds/ https://docs.googleusercontent.com/";//"https://spreadsheets.google.com/feeds/"; final protected static String GET_REQUEST_TOKEN_URL = "https://www.google.com/accounts/OAuthGetRequestToken?scope=" + URLEncoder.encode(SCOPE) + "&xoauth_displayname=" + URLEncoder.encode("TEST App"); – Anwer Dec 22 '11 at 12:17
  • Can you edit your question and add a complete snippet of the code you're using? – Vic Fryzel Dec 26 '11 at 22:33
  • The code you pasted in your comment is not readable and does not seem correct. Please fix your question. – Vic Fryzel Apr 07 '12 at 04:26