Best way to get a document ID

6,751 views
Skip to first unread message

Michel Pigassou

unread,
Dec 15, 2010, 10:14:54 AM12/15/10
to google-docum...@googlegroups.com
Hi.

I am facing an important problem, trying to allow a user to "select" a Google Document and accessing it (through its ID extracted from its XML) from my application.
I have started with a simple text field in which a user can paste a previously copied URL of a document. Using that URL (after cleaning it a little bit), I can browse the user's documents, find the document he wants and extract the data I need (for example the name of the document).

It works... in most cases!

It's a known fact that Google Docs URL are not consistent (see http://www.google.com/support/forum/p/apps-apis/thread?tid=49080c3c1c7564ea&hl=en), because not only the subdomain can change (docs0.google.com, docs3, spreadsheets9, etc.) but the key in the URL can also change!

So I'm asking, apart from the doc ID that the user can't infer, and without having to code a UI to display all its documents (seems to be very long, especially if you want to handle folders...), what is the best solution for you?

Vic Fryzel

unread,
Dec 15, 2010, 10:25:11 AM12/15/10
to google-docum...@googlegroups.com
Hey Michel,

Usually, those document IDs you're referring to are interchangeable.  However, as you've mentioned, it's hard to construct this URL by hand.

What I recommend instead is using the URLs provided by the Documents List API documents feed.  Here's a sample entry:
<entry gd:etag="'EVJVTBICRit7ImBq'">
  <id>https://docs.google.com/feeds/id/document%3A12345</id>
  ...
  <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/docs/2007#document" label="document"/>
  <category scheme="http://schemas.google.com/g/2005/labels" term="http://schemas.google.com/g/2005/labels#viewed" label="viewed"/>
  ...
  <content type="text/html" src="https://docs.google.com/feeds/download/documents/Export?docId=12345"/>
  <link rel="http://schemas.google.com/docs/2007#parent" type="application/atom+xml"
        href="https://docs.google.com/feeds/default/private/full/folder%3A12345" title="AFolderName"/>
  <link rel="alternate" type="text/html" href="https://docs.google.com/Doc?docid=12345&amp;hl=en"/>
  <link rel="self" type="application/atom+xml" href="https://docs.google.com/feeds/default/private/full/document%3A12345"/>
  <link rel="edit" type="application/atom+xml" href="https://docs.google.com/feeds/default/private/full/document%3A12345"/>
  <link rel="edit-media" type="text/html" href="https://docs.google.com/feeds/default/media/document%3A12345"/>
  <link rel="http://schemas.google.com/g/2005#resumable-edit-media" type="application/atom+xml"
      href="https://docs.google.com/feeds/upload/create-session/default/private/full/document%3A12345"/>
  ...
  <gd:feedLink rel="http://schemas.google.com/acl/2007#accessControlList"
       href="https://docs.google.com/feeds/default/private/full/document%3A12345/acl"/>
  <gd:feedLink rel="http://schemas.google.com/docs/2007/revisions"
       href="https://docs.google.com/feeds/default/private/full/document%3A12345/revisions"/>

Tons of links are provided, usually one for each case.  In this case I think I understand you're trying to export their document?  If so, you'll want the link given in the <content> element, something like this:

That link will always be correct, regardless of the specific document ID.

Thanks,
-Vic

Michel Pigassou

unread,
Dec 15, 2010, 10:43:40 AM12/15/10
to google-docum...@googlegroups.com
Thanks for your rapid answer.

My problem is not really about exporting a document. It for me to allow a user to access its documents from my application.

For that I use the URL of the document (copied and pasted from its browser), since the only other alternative I can think of is to provide a document selector inside my application.
Then I can match this URL to its corresponding document using the URL contained in the link rel="alternate" markup.

The problem is that apart from using the brower URL or displaying a list of its documents in my application I cannot find any other way to match them.

Vic Fryzel

unread,
Dec 15, 2010, 11:51:18 AM12/15/10
to google-docum...@googlegroups.com
Displaying a list would probably be a good way to go.  Can you try that?

-Vic

Michel Pigassou

unread,
Dec 15, 2010, 12:04:10 PM12/15/10
to google-docum...@googlegroups.com
Sure it is possible, but not desirable.
Our application aims at Google Apps users. Such a list is not managable with a huge amount of documents (50+).

A beautiful list would have to include pagination and labels for example, but the time to develop it would be quite longer than to allow copying/pasting a URL, you see?

Vic Fryzel

unread,
Dec 15, 2010, 12:07:20 PM12/15/10
to google-docum...@googlegroups.com
Or, perhaps you could implement an auto-complete search?

-Vic

Michel Pigassou

unread,
Dec 15, 2010, 12:17:41 PM12/15/10
to google-docum...@googlegroups.com
Yeah we have been discussing this alternative too, seems to be a good idea.

I realize that an amazing work has been done in Goole Docs, but do you know if the URL issue is considered as a real issue (I think that the URL is meant to be unique, and find kind of strange that in some cases it can change) or will be left as it is?

Michel Pigassou

unread,
Dec 15, 2010, 12:19:24 PM12/15/10
to google-docum...@googlegroups.com
PS : maybe that displaying the document ID somewhere in the "Share" overlay could be a solution for those who need to identify the document in the doc list feed provided by the API.

Vic Fryzel

unread,
Dec 15, 2010, 1:55:44 PM12/15/10
to google-docum...@googlegroups.com
Hi Michel,

When pulled from the feed, the <id> URLs do not change often at all.  The URLs via the UI change somewhat often because of different features and requirements.  The reason that these two things are not in sync is because of the different entry points.  It is assumed that with the GData feed, you will pull all entries first, and then search, where as in the UI, links to entries are provided in a bunch of different ways.

One thing you could do is pull their documents list, and compare alternate links (see my previous example) with the link that they've provided you.

-Vic

?ric Lestrade

unread,
Dec 17, 2010, 6:39:40 AM12/17/10
to google-docum...@googlegroups.com
Hi Vic.

Thanks for you interesting answers.

However, I am quite surprise that giving (and making available) a unique persistant ID to each Google Documents seems not to be considered as an important feature.

In the business world we constently have to include references to documents in other documents or emails.
When I use Lotus, I can write a message, drag and drop some files : the name of the files will appear inside the message and the actual files will be attached.

These sort of features, that I imagine online application will offer someday for online documents, probably need, some kind of unique persistent ID for each online document. This ID should be available when the user manipulates the "Google explorer" (page that lists all documents) or in the document itself. Because ID seems the best way to communicate with other applications. With the ID, other application can retreive metadata (as the name of the document) and, for instance, use them to make a link (with the name of the document).

The solution of browsing through documents and choosing one of them, each time the user wants to make a reference does not seem to be the perfect and only solution for the future.

Anyway, thank you for your time. In the meantime I think the best "light" solution is probably to use an auto-complete search, as you've suggested.

EL

Reply all
Reply to author
Forward
0 new messages