【发布时间】: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 从播放列表中删除“已删除视频”的其他方法?
【问题讨论】:
标签: python-3.x youtube-data-api playlist