Python - youtube.playlistItems().delete() 不适用于 [已删除的视频] (YouTube API v3)
Posted
技术标签:
【中文标题】Python - youtube.playlistItems().delete() 不适用于 [已删除的视频] (YouTube API v3)【英文标题】:Python - youtube.playlistItems().delete() doesn't work with [Deleted video] (YouTube API v3) 【发布时间】:2018-11-30 06:20:57 【问题描述】:我想清理我的 YouTube 频道的多个播放列表的 [已删除视频] 的残留。我正在使用此代码,但它不起作用。
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
CLIENT_SECRETS_FILE = "client_secrets.json"
YOUTUBE_READ_WRITE_SCOPE = "https://www.googleapis.com/auth/youtube"
def get_authenticated_service(args):
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
scope=YOUTUBE_READ_WRITE_SCOPE,
message=MISSING_CLIENT_SECRETS_MESSAGE)
storage = Storage("%s-oauth2.json" % sys.argv[0])
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run_flow(flow, storage, args)
return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
http=credentials.authorize(httplib2.Http()))
if __name__ == "__main__":
try:
args = argparser.parse_args()
youtube = get_authenticated_service(args)
youtube.playlistItems().delete(id="xxxxxxxxx").execute()
except HttpError as e:
print ("\nAn HTTP error %d occurred:\n%s" % (e.resp.status, e.content))
我收到此错误消息 (403)(禁止)
请求未正确授权删除指定播放列表项
"error":
"errors": [
"domain": "youtube.playlistItem",
"reason": "playlistItemsNotAccessible",
"message": "Forbidden",
"locationType": "parameter",
"location": "id"
],
"code": 403,
"message": "Forbidden"
即使从这里使用这个(试试这个 API):
https://developers.google.com/youtube/v3/docs/playlistItems/delete?hl=en-419
或这里
https://developers.google.com/youtube/v3/docs/playlistItems/delete?hl=es-419
我的凭据、我的开发人员密钥和我的 client_secrets.json 文件都很好,因为我以前使用过它并且它的工作原理。
有人知道发生了什么吗?或者有人知道使用 Python + Youtube API v3 从播放列表中删除“已删除视频”的其他方法?
【问题讨论】:
【参考方案1】:问题解决了:
如果你执行 PlaylistItems().list(),你会得到这个响应。
"items": [
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/Ktqi5NIapmys1w2V0FiorhFR-Uk\"",
"id": "UExES3pRck8tTUFDZndHV3Z0eXVaVHZXNENxNTNGYV9wNC4wMTcyMDhGQUE4NTIzM0Y5",
"snippet":
"publishedAt": "2018-06-06T13:43:17.000Z",
"channelId": "xxxxxxxxxxxxxxxxxx",
"title": "Deleted video",
"description": "This video is unavailable.",
"channelTitle": "xxxxxxxxxxxxxxxxxx",
"playlistId": "xxxxxxxxxxxxxxxxxxxxxxx",
"position": 0,
"resourceId":
"kind": "youtube#video",
"videoId": "D6NOeUfxCnM"
要从播放列表中删除项目,您必须使用它
"id": "UExES3pRck8tTUFDZndHV3Z0eXVaVHZXNENxNTNGYV9wNC4wMTcyMDhGQUE4NTIzM0Y5",
如果你使用这个"videoId": "D6NOeUfxCnM"
你会得到错误消息 (403)(Forbidden)
【讨论】:
感谢您提供答案,否则我会在同一件事上浪费数小时以上是关于Python - youtube.playlistItems().delete() 不适用于 [已删除的视频] (YouTube API v3)的主要内容,如果未能解决你的问题,请参考以下文章