Search code examples
pythongdatagdata-api

Extracting ID string from GDataEntry


I am playing around with Google's gdata API in python. More specificalyl, I am using the YouTube API, but I do not believe it will be relevant to this question.

I now have an object which is a subclass of GDataEntry and I am trying to get its id.

print entry.id

this fails as it cannot convert and Id object to a string. So I try:

print str(entry.id)

which serializes it to an XML string. What I really want is the textual content of the ID. I have been looking through the docs, and I was unable to find it so far. I am convinced this is really easy to do, but I cannot find the right method to get the text content of the Id object.


Solution

  • I'm pretty sure, that entry.id is of the type atom.Id which provides a ToString method and a text accessor. See the documentation here.

    So you'd like to write:

    print entry.id.text