API回复creativecommon时如何打印"this is creativeCommon"?

How to print "this is creativeCommon" when the API reply with creativecommon?

我正在尝试使用 YouTube 数据下载一些创意共享视频 API,但我对此很陌生,所以我被卡住了。如何前进?我想在 JSON 文件中找到 "license": "creativeCommon" 并打印 "this is creativeCommon" 我正在使用 python3

import json
import re
import urllib.request
from pytube import YouTube

api_key = API_KEY

video_id = "thD8Ad7pWps"
url = f"https://www.googleapis.com/youtube/v3/videos?part=status&id={video_id}&key={api_key}"

json_url = urllib.request.urlopen(url)
data = json.loads(json_url.read())

for item in data['items']:
    value = item.get('items')
    print (item.get('license'))
    if value in ['creativeCommon']:
     print ("this is creativeCommon")
    else:
     print ("this is not creativeCommon")

api回复

[{'kind': 'youtube#video', 'etag': '"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/ePPN2XwrH5k8OoNce4d83nQCMZk"', 'id': 'thD8Ad7pWps', 'status': {'uploadStatus': 'processed', 'privacyStatus': 'public', 'license': 'creativeCommon', 'embeddable': True, 'publicStatsViewable': True}}]

我预计这是 return 这是 creativeCommon 但它 returned 这不是 creativeCommon。

以下是 return编辑的:

KeyError                                  Traceback (most recent call last)
<ipython-input-3-0a69a7438b8f> in <module>
     13 
     14 for item in data['items']:
---> 15     value = data[0]['status']['license']
     16 
     17     if value in ['creativeCommon', 'CREATIVECOMMON']:

KeyError: 0

您可以在下面更改:

value = item.get('items')

value = item['status']['license']

这会给你结果:creativeCommon