Unable to Delete Videos with the Youtube Data API

2024/9/25 23:19:53

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_EMAILyt_service.password = YOUTUBE_SECRET_PASSWORDyt_service.source = YOUTUBE_SOURCEyt_service.developer_key = YOUTUBE_SECRET_DEVELOPER_KEYyt_service.client_id = YOUTUBE_CLIENT_IDyt_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?

Answer

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).

https://en.xdnf.cn/q/71523.html

Related Q&A

LLDB Python scripting in Xcode

Ive just discovered this handy feature of LLDB that allows me to write Python scripts that have access to variables in the frame when Im on a breakpoint in LLDB. However Im having a few issues when usi…

What technologies exist to create stand alone executables for Python 3?

Other than cx_Freeze, are there any other current maintained tool suites to generate stand alone executables for Python 3k?Are there any other techniques for minimizing preinstallation requirements un…

running multiple threads in python, simultaneously - is it possible?

Im writing a little crawler that should fetch a URL multiple times, I want all of the threads to run at the same time (simultaneously).Ive written a little piece of code that should do that.import thre…

Drawing bounding rectangles around multiple objects in binary image in python

I am trying to write some easy code in python to produce bounding rectangles around objects in a binary image, where there may be 1 or more objects. This is fairly easy to achieve with cv2.boundingRec…

Replicating YEARFRAC() function from Excel in Python

So I am using python in order to automate some repetitive tasks I must do in excel. One of the calculations I need to do requires the use of yearfrac(). Has this been replicated in python?I found this…

creating a pandas dataframe from a database query that uses bind variables

Im working with an Oracle database. I can do this much:import pandas as pdimport pandas.io.sql as psqlimport cx_Oracle as odbconn = odb.connect(_user +/+ _pass +@+ _dbenv)sqlStr = "SELECT * FROM c…

Is there a docstring autocompletion tool for jupyter notebook?

I am looking for a tool/extension that helps you writing python docstrings in jupyter notebook. I normally use VS code where you have the autodocstring extension that automatically generates templates …

Long to wide data. Pandas

Im trying to take my dataframe from a long format in which I have a column with a categorical variable, into a wide format in which each category has its own price column. Currently, my data looks like…

How to wrap text in Django admin(set column width)

I have a model Itemclass Item(models.Model):id = models.IntegerField(primary_key=True)title = models.CharField(max_length=140, blank=True)description = models.TextField(blank=True)price = models.Decima…

Problems compiling mod_wsgi in virtualenv

Im trying to compile mod_wsgi (version 3.3), Python 2.6, on a CentOS server - but under virtualenv, with no success. Im getting the error:/usr/bin/ld:/home/python26/lib/libpython2.6.a(node.o):relocatio…