video - access youtube api using keyword in python -


i want access youtube api next project not getting how use python code available:

the code using

#!/usr/bin/python  apiclient.discovery import build apiclient.errors import httperror oauth2client.tools import argparser   # set developer_key api key value apis & auth > registered apps # tab of #   https://cloud.google.com/console # please ensure have enabled youtube data api project. developer_key = "replaced_my_api_key" youtube_api_service_name = "youtube" youtube_api_version = "v3"  def youtube_search(options):   youtube = build(youtube_api_service_name, youtube_api_version,     developerkey=developer_key)    # call search.list method retrieve results matching specified   # query term.   search_response = youtube.search().list(     q=options.q,     part="id,snippet",     maxresults=options.max_results   ).execute()    videos = []   channels = []   playlists = []    # add each result appropriate list, , display lists of   # matching videos, channels, , playlists.   search_result in search_response.get("items", []):     if search_result["id"]["kind"] == "youtube#video":       videos.append("%s (%s)" % (search_result["snippet"]["title"],                                  search_result["id"]["videoid"]))     elif search_result["id"]["kind"] == "youtube#channel":       channels.append("%s (%s)" % (search_result["snippet"]["title"],                                    search_result["id"]["channelid"]))     elif search_result["id"]["kind"] == "youtube#playlist":       playlists.append("%s (%s)" % (search_result["snippet"]["title"],                                     search_result["id"]["playlistid"]))    print "videos:\n", "\n".join(videos), "\n"   print "channels:\n", "\n".join(channels), "\n"   print "playlists:\n", "\n".join(playlists), "\n"   if __name__ == "__main__":     argparser.add_argument("--q", help="search term", default="google")     argparser.add_argument("--max-results", help="max results", default=25)     args = argparser.parse_args()     try:     youtube_search(args)   except httperror, e:     print "an http error %d occurred:\n%s" % (e.resp.status, e.content) 

i want access video id

i not getting should pass search string argument .

thanks in advance,

 argparser.add_argument("--q", help="search term", default="google") 

here instead of "google" should put string want search.

let's want find witcher 3 videos.

to_search = "witcher 3" argparser.add_argument("--q", help="search term", default=to_search) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -