I have a list with videos that I would like to add to a playlist with the help of the youtube api v3. I have oauth set up in my code as well as the developers console:
# Sample Python code for youtube.channels.list# See instructions for running these code samples locally:# https://developers.google.com/explorer-help/code-samples#pythonimport osimport google_auth_oauthlib.flowimport googleapiclient.discoveryimport googleapiclient.errorsscopes = ["https://www.googleapis.com/auth/youtube"]# Disable OAuthlib's HTTPS verification when running locally.# *DO NOT* leave this option enabled in production.os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"api_service_name = "youtube"api_version = "v3"client_secrets_file = "client_secret_xxx.apps.googleusercontent.com.json"# Get credentials and create an API clientflow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file( client_secrets_file, scopes)credentials = flow.run_console()youtube = googleapiclient.discovery.build( api_service_name, api_version, credentials=credentials)Then I use this function to add the videos to my playlist:
def add_video_to_playlist(youtube,videoID,playlistID): add_video_request=youtube.playlistItems().insert( part="snippet", body={'snippet': {'playlistId': playlistID, 'resourceId': {'kind': 'youtube#video','videoId': videoID } #'position': 0 }} ).execute()The scopes in my developer account are set:Screenshot
The error message I get is the following:
HttpError: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet&alt=json returned "Forbidden". Details: "[{'message': 'Forbidden', 'domain': 'youtube.playlistItem', 'reason': 'playlistItemsNotAccessible'}]">Where am I doing something wrong?