Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

How to append 'null' or 'n/a' value when extracting data from Youtube API

$
0
0

My code allows to call data from Youtube API and put them into list to form a datafram.However, when the API cannot access the 'items' it returns error. In order to avoid errors, I need to append 'n/a' or 'null' and pass when the API cannot access certain items.

def get_channel_stats(youtube, channel_ids):all_data = []for i in range(0, len(channel_ids), 50):    request = youtube.channels().list(                part='snippet,contentDetails,statistics',                id = ','.join(channel_ids[i:i+50]))    response = request.execute()    for i in range(len(response['items'])):        data = dict(channel_name = response['items'][i]['snippet']['title'],                    published_date = response['items'][i]['snippet']['publishedAt'],                    subscribers = response['items'][i]['statistics']['subscriberCount'],                    views = response['items'][i]['statistics']['viewCount'],                    total_videos = response['items'][i]['statistics']['videoCount'],                    playlist_id = response['items'][i]['contentDetails']['relatedPlaylists']['uploads'],                    retrieved_date = date.today().strftime('%Y/%m/%d')                                  )        all_data.append(data)return all_data

Any directions or advice would be very helpful.

Thank you in advanced.


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>