I successfully implemented the example
http://code.google.com/intl/de-DE/apis/documents/docs/2.0/developers_guide_java.html
for username / password based authentification.
I now want to use this approach for 2 legged authentification against
our domain, but the last step (downloading of documents) fails
com.google.gdata.util.AuthenticationException: Unauthorized.
My code looks roughly like that:
1) WORKS: Configuration docsService:
DocsService docsService = new DocsService(applicationName);
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey(authentificationManager.getOauthKey());
oauthParameters.setOAuthConsumerSecret(authentificationManager.getOauthSecret());
docsService.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
2) WORKS: fetching feed (with xoauth_requestor_id)
DocumentQuery query = new DocumentQuery(
new URL("https://docs.google.com/feeds/default/private/full"));
query.setStringCustomParameter("xoauth_requestor_id",
userToBackupWithEmail);
DocumentListFeed allEntries = new DocumentListFeed();
DocumentListFeed tempFeed = docsService.getFeed(query,
DocumentListFeed.class);
//paging through results works...
3) DOES NOT WORK: downloading fails with
com.google.gdata.util.AuthenticationException: Unauthorized
//entry is a DocumentListEntry
String exportUrl = ((MediaContent) entry.getContent()).getUri() +
"&exportFormat=" + fileExtension;
normally I would do
UserToken docsToken = (UserToken)
docsService.getAuthTokenFactory().getAuthToken();
docsService.setUserToken(docsToken.getValue());
=> but I guess this does not work for oauth....
I tried to add
exportUrl += "&xoauth_requestor_id="+userNameToBackup;
but that did not change anything...
When I try to download like so:
MediaContent mc = new MediaContent();
mc.setUri(exportUrl);
MediaSource ms = docsService.getMedia(mc);
I am getting the
com.google.gdata.util.AuthenticationException: Unauthorized
the exportUrl seems to be fine:
https://docs.google.com/feeds/download/drawings/Export?id=1ssdffsfsfasf0YhLwM&xoauth_requestor_id=myuse...@mydomain.com&exportFormat=pdf
Adding / removing xoauth_requestor_id does not change anything...
Any ideas how to download individual files from google via 2legged oauth?
Many thanks in advance :)
Best,
Raphael
--
inc: http://ars-machina.raphaelbauer.com
tech: http://ars-codia.raphaelbauer.com
web: http://raphaelbauer.com
Okay. After some investigation I noticed that sometimes the
xoauth_requestor_id is added automatically, sometimes not.
My research led me to the following:
xoauth_request_id is added by gdata when DocumentListEntry.getType is:
- document
- drawing
- presentation
xoauth_request_id has to be added manually when DocumentListEntry.getType is:
- pdf
- spreadsheet
- file
Can somebody confirm that this makes sense?
Is this somewhere written in the documentation? Maybe I missed this -
but if it's not documented it would be great to add this information
somewhere... :)
Thanks,
Raphael