【问题标题】:Python youtube api status.rejectionReason [closed]Python youtube api status.rejectionReason [关闭]
【发布时间】:2018-11-16 20:18:57
【问题描述】:

我查看了这里的文档:https://developers.google.com/youtube/v3/docs/videos 但我不确定如何使用 python 访问 status.rejectionReason。我一直在使用 youtube-uploader 进行上传,我不相信有任何命令可以返回视频被拒绝的原因。理想的情况是获取我所有视频的列表,检查哪些被拒绝,然后返回被拒绝的链接。

【问题讨论】:

  • 除非你添加你尝试过的代码,它的效果,它应该有的效果以及出了什么问题,这将很快被否决和近距离投票。我们不会为您编写代码,我们会帮助修复 您的代码 ...再次查看 how to askon-topic 如果您有(一个)特定问题(每个问题),请提供您的代码作为Minimal, Complete, and Verifiable example

标签: python youtube-api youtube-data-api


【解决方案1】:

据我所知,rejectionReason 采用 JSON“视频资源”格式。您可以使用 Python 的内置 JSON 库来访问它:

from json import load

with open('video.json') as file:  # Opens the JSON file and assigns it to the variable 'file' within the loop
    data = load(f)  # Loads the file into a dictionary which you can access with key:value pairs

网站上作为示例提供的 JSON 文件遵循以下格式拒绝原因:

"status": {
    "uploadStatus": string,
    "failureReason": string,
    "rejectionReason": string,
    "privacyStatus": string,
    "publishAt": datetime,
    "license": string,
    "embeddable": boolean,
    "publicStatsViewable": boolean
  }

所以我相信你的最终脚本应该是这样的:

from json import *


def get_rejection_reason(file):
    with open(file) as f:
        data = load(f)

    return data["status"]["rejectionReason"]

get_rejection_reason("video.json")

【讨论】:

    猜你喜欢
    • 2012-08-14
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 2012-07-08
    • 2019-12-15
    • 2012-10-09
    • 2015-07-18
    相关资源
    最近更新 更多