I have the following error:
line 57, in <module>
for feed in feedjson['items']:
KeyError: 'items'
My objective is to connect to the Google API and download in a CSV some data of videos in range time.
Thanks in advance.
This is the code:
line 57, in <module>
for feed in feedjson['items']:
KeyError: 'items'
My objective is to connect to the Google API and download in a CSV some data of videos in range time.
Thanks in advance.
This is the code:
DEVELOPER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" import requests import csv from datetime import datetime, timedelta, date datosYT_Ufo=open("datosYT_Ufo2.csv", "w" , encoding='utf-8') csvwriter = csv.writer(datosYT_Ufo, delimiter=";") FormatoFecha ='2005-06-01' FormatoFechaStr = datetime.strptime(FormatoFecha, '%Y-%m-%d') while FormatoFechaStr < datetime.now(): yearEnFormatoAdecuado = str(FormatoFechaStr) + "T00:00:00Z" url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=UFO&order=viewCount®ionCode=US&maxResults=50&type=video&snippet.publishedAt&snippet.description&key=xxxxxxxxxxxxxxx&publishedBefore=" + yearEnFormatoAdecuado print (url) feed = requests.request(method="GET", url=url) feed_json = feed.json() print("Vídeos del año: " + str(FormatoFechaStr)) for feed in feed_json['items']: Video_title = feed['snippet']['title'] Video_description = feed['snippet']['description'] Video_publishedAt = feed['snippet']['publishedAt'] print (Video_title) csvwriter.writerow([Video_title, Video_description, Video_publishedAt]) #year += 1 FormatoFechaStr += timedelta(days=1) print (FormatoFechaStr) print ("--------------------------------")