Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Delete Videos with the Youtube Data API

Can't get deleting videos to work using the Youtube Data API. I'm using the Python Client Library.

All of this seems straight from the docs, so I'm really confused as to why it's not working. Here's my function:

def delete_youtube_video_by_id(video_id):
    yt_service = gdata.youtube.service.YouTubeService()
    yt_service.email = YOUTUBE_EMAIL
    yt_service.password = YOUTUBE_SECRET_PASSWORD
    yt_service.source = YOUTUBE_SOURCE
    yt_service.developer_key = YOUTUBE_SECRET_DEVELOPER_KEY
    yt_service.client_id = YOUTUBE_CLIENT_ID
    yt_service.ProgrammaticLogin()
    video_entry = yt_service.GetYouTubeVideoEntry(video_id=video_id)
    response = yt_service.DeleteVideoEntry(video_entry)
    return response

From the docs, this should return True if the video is successfully deleted. However, it returns None:

>>> response = delete_youtube_video_by_id('my_youtube_video_id')
>>> type(response)
<type 'NoneType'>
>>> 

And the video is not deleted. I know the credentials are good, because they are the same credentials I used to upload the video in the first place, and I know the id is good, because I got it directly from my channel in youtube.

Any ideas?

like image 306
Clay Wardell Avatar asked Jan 07 '13 16:01

Clay Wardell


1 Answers

I'm fairly sure that this is due to the need to get the video entry from your uploads feed, not the general video feed. Otherwise the entry isn't editable.

This would translate to

video_entry = yt_service.GetYouTubeVideoEntry('https://gdata.youtube.com/feeds/api/users/default/uploads/VIDEO_ID')

The Python GData client library still uses v1 of the Data API, which has been deprecated for a long time now, and the client library in general is not well-maintained.

I'd recommend switching to v3 and the corresponding new client library as that's definitely the environment of the future. We have a handful of Python samples available now, and while there isn't specifically one for deleting a video, it should look something like

youtube.videos().delete(id=VIDEO_ID).execute()

(assuming youtube is a properly authorized YouTube client interface, following the existing examples on that page).

like image 144
Jeff Posnick Avatar answered Sep 28 '22 02:09

Jeff Posnick