How to integrate Google Document Viewer programmatically

I’m working on a project where I need to integrate Google’s document viewer functionality into my web application. I want users to be able to upload documents and then display them using Google’s viewer.

I’ve been looking into the Google Docs API and found some discussions about using embed links with specific schemas. However, when I try to implement this in Java, I keep running into issues.

Here’s what I’m trying to accomplish:

public class DocumentViewerService {
    private DocsService docService;
    
    public String createEmbedLink(String fileName, InputStream fileContent) {
        try {
            DocumentListEntry newEntry = new DocumentListEntry();
            newEntry.setTitle(new PlainTextConstruct(fileName));
            
            // This is where I'm having trouble
            newEntry.addExtension(new XmlNamespace("http://schemas.google.com/docs/2007#embed"));
            
            URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full");
            DocumentListEntry insertedEntry = docService.insert(feedUrl, newEntry);
            
            return insertedEntry.getDocumentLink().getHref();
        } catch (Exception e) {
            throw new RuntimeException("Failed to create embed link", e);
        }
    }
}

The error I’m getting is:
com.google.gdata.util.InvalidEntryException: Invalid request URI

Can anyone help me understand what I’m doing wrong? Is there a correct way to set the namespace for embedded documents in the Google Docs API?

Same issue I ran into last year - those old Google Docs APIs don’t work anymore. Skip the Drive API auth mess and just use iframe embeds instead. For public files, use https://docs.google.com/gviewer?url=YOUR_FILE_URL&embedded=true. No OAuth hassle and it handles PDFs and Office docs just fine.

That Google Documents List API died in 2012 and got shut down completely in 2015. Those namespaces won’t work - they’re dead code at this point. You’ve got two ways to handle document viewing now. Option one: use Google Drive API v3 with Drive’s built-in viewer. Upload your files to Drive and grab the webViewLink property to display them. Option two: use Google Docs Viewer with public URLs like https://docs.google.com/viewer?url=YOUR_DOCUMENT_URL&embedded=true. I’ve used the Drive API route in production and it works well. You’ll need OAuth2 auth, then upload docs through the Drive API and generate shareable links with the right permissions. The viewer handles most document formats without issues. Ditch those old DocumentListEntry classes and XML namespaces - they’re completely useless now. Go with the modern Drive API and you’ll actually get somewhere.

Had this exact problem six months ago building a document management system. You’re using deprecated API endpoints that Google killed off years ago. Here’s what fixed it for me: ditch the old approach and use Google Drive API v3 with their viewer service instead. Upload files straight to Google Drive via the Drive API, then build viewer URLs yourself. Grab the file ID from the upload response and construct URLs like https://drive.google.com/file/d/FILE_ID/preview for embedding. You’ll need proper OAuth2 auth and correct sharing permissions on your files. That DocumentListEntry class doesn’t exist anymore in current Google APIs - that’s why you’re getting the invalid request URI error. Use the Drive API’s File resource instead and you’ll dodge those namespace issues.