Which url for getting json data for youtube uploaded videos from a user on api 3.0
This is the way to grab the last 50 (maximum allowed) videos of a user with Youtube with Api 3.0
//search channels of user
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername={USERNAME}&key={KEY}
//search playlist items of upload channel
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId={PLAYLIST}&key={KEY}
//search videos of the playlist items of the upload channel
https://www.googleapis.com/youtube/v3/videos?part=id,snippet,contentDetails,status&id=BBfPP0rTjxo,o04cSB5afGc&maxResults=50&key={KEY}
Version 3 of the YouTube Data API can be found here:
https://developers.google.com/youtube/v3/
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername={USERNAME}&key={YOUR_API_KEY}
Use the following code.
#!/usr/bin/pythonfrom apiclient.discovery import buildfrom apiclient.errors import HttpErrorDEVELOPER_KEY = "your key"YOUTUBE_API_SERVICE_NAME = "youtube"YOUTUBE_API_VERSION = "v3"def youtube_search(search_item): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) search_response = {} search_results = [] search_response = youtube.search().list( q=search_item, type="video", part="id,snippet", maxResults=50 ).execute() search_results.append(search_response) if search_response.has_key('pageInfo'): if search_response['pageInfo'].has_key('totalResults'): totalResults = search_response['pageInfo']['totalResults'] for i in range(len(range(50,totalResults,50))): if search_response.has_key('nextPageToken'): pT = search_response['nextPageToken'] search_response = {} search_response = youtube.search().list( q=search_item, type="video", part="id,snippet", pageToken = pT, maxResults=50, ).execute() print "ok" time.sleep(1) search_results.append(search_response) for i in search_results: for j in i['items']: statistics = search_video(j['id']['videoId']) j['statistics']=statistics return search_resultsdef search_video(id): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) data = youtube.videos().list( id=id, part="statistics" ).execute() return data['items'][0]['statistics']def main(): #call the youtube_search function by passing the usernameof the user in youtube #eg #data = youtube_search('Google')if __name__ == '__main__': main()
Use this code for getting json data for youtube uploaded videos from a user on api 3.0 .You will get maximum 500 videos per user.The api key will be available https://console.developers.google.com/