0

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>.">
SeyiA
  • 95
  • 6
  • please edit your question and include a working example. there is not enough code here to recreate the issue. https://developers.google.com/youtube/v3/code_samples/python_appengine – Linda Lawton - DaImTo Dec 04 '20 at 14:25
  • @DaImTo Can't use the examples in that link on there because they are based Python 2x code but I've pulled up my old code that used to work. It's more extensive and should provide more context on my issue. It's a different error so I have updated the title and summary. – SeyiA Dec 04 '20 at 14:55
  • Here is the answer to your question: [Youtube Data API: The request cannot be completed because you have exceeded your quota, INSUFFICIENT\_TOKENS](https://stackoverflow.com/a/63211212/8327971). The key thing is (quote from you): *I haven't used this API key in a long time.* – stvar Dec 04 '20 at 15:32

0 Answers0