无法使用 Youtube Data API 删除视频 [英] Unable to Delete Videos with the Youtube Data API

查看:33
本文介绍了无法使用 Youtube Data API 删除视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法使用 Youtube Data API 删除视频.我正在使用 Python 客户端库.

所有这些似乎都直接来自文档,所以我真的很困惑为什么它不起作用.这是我的功能:

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)响应 = yt_service.DeleteVideoEntry(video_entry)返回响应

从文档中,如果视频被成功删除,这应该返回 True.但是,它返回 None:

<预><代码>>>>response = delete_youtube_video_by_id('my_youtube_video_id')>>>类型(响应)<输入'NoneType'>>>>

并且视频没有被删除.我知道凭据很好,因为它们与我最初上传视频时使用的凭据相同,而且我知道 id 很好,因为我直接从 youtube 上的频道获得了它.

有什么想法吗?

解决方案

我很确定这是因为需要从上传的供稿中获取视频条目,而不是一般的视频供稿.否则该条目不可编辑.

这将转化为

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

Python GData 客户端库仍然使用 Data API 的 v1,该版本现已弃用很长时间,并且客户端库总体上没有得到很好的维护.

我建议切换到 v3 和相应的 新客户端库,因为这绝对是未来的环境.我们有一个现在可用的少数 Python 示例,虽然没有专门的一个用于删除视频,它应该看起来像

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

(假设 youtube 是经过适当授权的 YouTube 客户端界面,遵循该页面上的现有示例).

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?

解决方案

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

这篇关于无法使用 Youtube Data API 删除视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆