def check_api_key(key):
 url = 'https://www.googleapis.com/youtube/v3/i18nLanguages'
 query = {'part': 'snippet', 'fields': 'items/id', 'key': key}
 try:
  urlopen(((url + '?') + urlencode(query))).read()
  message = (("The key, '" + key) + "' will now be used for API requests.")
  pafy.set_api_key(Config.API_KEY.get)
  return dict(valid=True, message=message)
 except HTTPError:
  message = (("Invalid key or quota exceeded, '" + key) + "'")
  return dict(valid=False, message=message)

def check_api_key ( key ) : url = 'https://www.googleapis.com/youtube/v3/i18nLanguages' query = { 'part' : 'snippet' , 'fields' : 'items/id' , 'key' : key } try : urlopen ( ( ( url + '?' ) + urlencode ( query ) ) ) . read ( ) message = ( ( "The key, '" + key ) + "' will now be used for API requests." ) pafy . set_api_key ( Config . API_KEY . get ) return dict ( valid = True , message = message ) except HTTPError : message = ( ( "Invalid key or quota exceeded, '" + key ) + "'" ) return dict ( valid = False , message = message )
validate an api key by calling an api endpoint with no quota cost .