views:

274

answers:

2

Hi, how do I get the author/username from an object using:

GetYouTubeVideoEntry(video_id=youtube_video_id_to_output)

I'm using Google's gdata.youtube.service Python library

Thanks in advance! :)

A: 

Have you tried something like this?

foo = GetYouTubeVideoEntry(video_id=youtube_video_id_to_output)
foo.author

The docs for YouTubeVideoEntry aren't great, but the __init__ method seems to accept an author.

Hank Gay
foo.author returns an atom object. I did dir() on it and there's no member that holds the author/username. It's wierd..
alimango
+1  A: 

So because YouTube's API is based on GData, which is based on Atom, the 'author' object is an array with name objects, which can contain names, URLs, etc.

This is what you want:

>>> client = gdata.youtube.service.YouTubeService()
>>> video = client.GetYouTubeVideoEntry(video_id='CoYBkXD0QeU')
>>> video.author[0].name.text
'GoogleDevelopers'
Steph Liu
Thanks for the solution and explanation Steph, it's all working now :)
alimango