I seem to get this error but can't quite pinpoint what the issue is.
My API Key seems fine, there's no restrictions and I haven't used this API key in a long time. I don't see how I'm going over a quota when I barely use it.
#Import modules
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.tools import argparser
import pandas as pd
import pprint
import matplotlib.pyplot as plt
#Set up YouTube credentials
DEVELOPER_KEY = key.DEVELOPER_KEY
YOUTUBE_API_SERVICE_NAME = key.YOUTUBE_API_SERVICE_NAME
YOUTUBE_API_VERSION = key.YOUTUBE_API_VERSION
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,developerKey=key.DEVELOPER_KEY)
#-------------Build YouTube Search------------#
def youtubeSearch(query, max_results=50,order="relevance", token=None, location=None, location_radius=None):
#search upto max 50 videos based on query
search_response = youtube.search().list(
q=query,
type="video",
pageToken=token,
order = order,
part="id,snippet",
maxResults=max_results,
location=location,
locationRadius=location_radius).execute()
print("Search Completed...")
print("Total results: {0} \nResults per page: {1}".format(search_response['pageInfo']['totalResults'], search_response['pageInfo']['resultsPerPage']))
print("Example output per item, snippet")
print(search_response['items'][0]['snippet'].keys())
#Assign first page of results (items) to item variable
items = search_response['items'] #50 "items"
#Assign 1st results to title, channelId, datePublished then print
title = items[0]['snippet']['title']
channelId = items[0]['snippet']['channelId']
datePublished = items[0]['snippet']['publishedAt']
print("First result is: \n Title: {0} \n Channel ID: {1} \n Published on: {2}".format(title, channelId, datePublished))
return search_response
youtubeSearch("Drake Future")
This error appears.
HttpError: <HttpError 403 when requesting https://youtube.googleapis.com/youtube/v3/search?q=Drake+Future&type=video&order=relevance&part=id%2Csnippet&maxResults=50&key=[MY API KEY]&alt=json "The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.">