+ # tubestates/youtube_api.py
+
+upload_playlist_ID = channel_data['upload_playlist_ID']
+
+video_response = []
+next_page_token = None
+while True:
+ # obtaining video ID + titles
+ playlist_request = self.youtube.playlistItems().list(
+ part='snippet,contentDetails',
+ maxResults=50, # API Limit is 50
+ pageToken=next_page_token,
+ playlistId=upload_playlist_ID,
+ )
+ playlist_response = playlist_request.execute()
+ # isolating video ID
+ vid_subset = [ vid_ID['contentDetails']['videoId']
+ for vid_ID in playlist_response['items'] ]
+ # retrieving video statistics
+ vid_info_subset_request = self.youtube.videos().list(
+ part='snippet,contentDetails,statistics',
+ id=vid_subset
+ )
+ vid_info_subset_response = vid_info_subset_request.execute()
+ video_response.append(vid_info_subset_response)
+ # obtaining page token
+ next_page_token = playlist_response.get('nextPageToken') # get method used because token may not exist
+ if next_page_token is None:
+ break
+
+df = pd.json_normalize(video_response, 'items')
+return df
+
+