How to ignore videos with like count disabled while using YouTube Data API V3

  python-3.x, youtube-api, youtube-data-api

In a YouTube search result, some videos have their likes hidden. My code fails when it reaches those videos:

KeyError : 'likeCount'.

Is there a way to ignore such videos and continue with my iteration?

request = youtube.videos().list(part = "snippet,statistics", id = LIST)
A = request.execute()
for j in range(len(A['items'])):
  Data.append({
    'Views': A['items'][j]['statistics']['viewCount'],
    'Likes': A['items'][j]['statistics']['likeCount'],
    'Dislikes': A['items'][i]['statistics']['dislikeCount']
  })

Source: Python-3x Questions

LEAVE A COMMENT