Hey everyone,
I’m trying to figure out how to use the Google Docs Viewer API. My goal is to upload a document and get a URL that I can embed on my website. Right now, I can only view public documents by adding their URL as a parameter like this: http://docs.google.com/viewer?url=xxxxxxxxxx
.
Is there another way to do this? I’d like to upload documents to a user’s Google account and then have them only be able to view the document, not edit it.
I’ve been looking into setting the ‘xmlns’ attribute to ‘http://schemas.google.com/docs/2007#embed’ on the document entry, but I’m getting an InvalidEntryException. The error message says:
com.google.gdata.util.InvalidEntryException: Invalid request URI
GData invalidRequestUri Invalid request URI
Does anyone have a Java code example that shows how to do this correctly? I’d really appreciate any help or suggestions to solve this problem. Thanks in advance!
I’ve actually tackled a similar challenge in one of my projects. Instead of using the Google Docs Viewer API directly, I found success with the Google Drive API. Here’s what worked for me:
- Upload the document to Google Drive using the Drive API.
- Set the sharing permissions to ‘Anyone with the link can view’.
- Retrieve the file’s ID from the API response.
- Construct the viewer URL like this:
https://drive.google.com/file/d/{FILE_ID}/preview
This approach gives you more control over the document’s accessibility and still allows for embedding. It’s not exactly what you asked for, but it achieves the same end result. The viewer URL can be easily embedded in an iframe on your website.
Just remember to handle authentication properly and manage your API quota. Hope this helps!
hey there! i’ve been messing around with the google docs api too. didn’t have much luck with the viewer api directly, but you could try using google drive api instead. upload docs there, set sharing settings to ‘view only’, then grab the embed url. might be a workaround for what ur trying to do. good luck!
I’ve encountered similar issues with the Google Docs Viewer API. In my experience, a more reliable approach is to use the Google Drive API in combination with the Google Picker. This method allows for secure document uploads and controlled viewing.
Here’s a brief overview:
- Implement Google Picker for document selection.
- Use Drive API to upload and manage documents.
- Set appropriate sharing permissions.
- Generate a viewer URL using the file ID.
This approach provides better control over document access and visibility. It’s worth noting that you’ll need to handle OAuth 2.0 authentication for secure access to user accounts.
For Java implementation, check out the Google Drive API client library. It simplifies many of these operations and provides robust error handling.