Created
May 28, 2019 02:40
-
-
Save portothree/47a8b28970d5b21770e2ae8bfc1a86c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apiclient.discovery import build | |
from apiclient.errors import HttpError | |
from oauth2client.tools import argparser | |
import pprint | |
pp = pprint.PrettyPrinter(indent=4) | |
DEVELOPER_KEY = "" | |
YOUTUBE_API_SERVICE_NAME = "youtube" | |
YOUTUBE_API_VERSION = "v3" | |
def youtube_search(q, max_results=50,order="relevance", token=None, location=None, location_radius=None): | |
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, | |
developerKey=DEVELOPER_KEY) | |
search_response = youtube.search().list( | |
q=q, | |
type="video", | |
pageToken=token, | |
order = order, | |
part="id,snippet", | |
maxResults=max_results, | |
location=location, | |
locationRadius=location_radius | |
).execute() | |
videos = [] | |
for search_result in search_response.get("items", []): | |
if search_result["id"]["kind"] == "youtube#video": | |
videos.append(search_result) | |
try: | |
nexttok = search_response["nextPageToken"] | |
return(nexttok, videos) | |
except Exception as e: | |
nexttok = "last_page" | |
return(nexttok, videos) | |
def geo_query(video_id): | |
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, | |
developerKey=DEVELOPER_KEY) | |
video_response = youtube.videos().list( | |
id=video_id, | |
part='snippet, recordingDetails, statistics' | |
).execute() | |
return video_response | |
tests = youtube_search("Bolacha") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment