Category : youtube-api

I use this sample of code I found on the YouTube dev help site to post comment on a video # -*- coding: utf-8 -*- # Sample Python code for youtube.commentThreads.insert # See instructions for running these code samples locally: # https://developers.google.com/explorer-help/guides/code_samples#python import os import google_auth_oauthlib.flow import googleapiclient.discovery import googleapiclient.errors scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"] def main(): ..

Read more

I like to sort and update youtube playlist items by my own criteria but the problem is that I couldn’t get my head around how to update the whole playlist items position at once. As request body required data in the following format: body = { "snippet": { "playlistId": "PLyR_eqaLz2hmBPeDYO3pyXaqexCIV-PGp", "resourceId": { "kind": "youtube#video", "videoId": ..

Read more

Im using Youtube api to get 10 random youtube channel id’s and put them in a list, so i created a function to return this list : def youtube_search(): all_data = [] search_response = youtube.search().list( part=’snippet’, maxResults=10, location=None, locationRadius=None, regionCode = ‘TN’, ) response = search_response.execute() for i in range(len(response[‘items’])): data = response[‘items’][i][‘snippet’][‘channelId’] all_data.append(data) return ..

Read more

I would like to add the Youtube api to my project to load video from my site, until now i just used languages like Html, css, javascript, php and sql and now i saw at this link https://learndataanalysis.org/how-to-upload-a-video-to-youtube-using-youtube-data-api-in-python/ a tutorial about how implement the youtube api using python (where i have 0 knowledge). These are ..

Read more

So im checking out youtube api, and just have a basic code like: from googleapiclient.discovery import build api_key = ‘MYAPIKEY’ youtube = build(‘youtube’, ‘v3′, developerKey=api_key) request = youtube.channels().list( part=’statistics’, forUsername=’schafer5′ ) response = request.execute() print(response) And i get the desired output as well: C:Python_VENVstubenvScriptspython.exe C:/Users/Prashant(Gaz)/venvPycharmProjects/tube_api/main.py {‘kind’: ‘youtube#channelListResponse’, ‘etag’: ‘4UXC8tQ1TiWDHFYcwMN6SAfmOwI’, ‘pageInfo’: {‘totalResults’: 1, ‘resultsPerPage’: 5}, ‘items’: ..

Read more

I have a script that loops through some YouTube videos and adds them to a playlist: for page in pages: add_video_to_playlist(youtube,upsert_id,my_playlist) def add_video_to_playlist(youtube_obj,video_id,yt_pl_id): request = youtube_obj.playlistItems().insert( part="snippet", body={ "snippet": { "playlistId": yt_pl_id, #"position": 0, "resourceId": { "kind": "youtube#video", "videoId": video_id } } } ) try: response = request.execute() print(response[‘snippet’][‘title’]) except HttpError as err: return "Error: ..

Read more

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’], ..

Read more

I’m writing an application using Python that requests videos’ closed captions. The code looks something like this: videoID = getVideo(videoURL) request = youtube.videos().list( part="snippet,contentDetails,statistics", id=videoID ) response = request.execute() items = response.get("items")[0] contentDetails = items["contentDetails"] caption = contentDetails["caption"] if(caption): print("Video contains closed captions!") else: print("Video does not contain closed captions.") #get caption info if(caption): caption_info ..

Read more