How can I use Python to access the YouTube API?
-
-
Answer:
YouTube's current version of their API works using gdata and so you need to get the gdata Python module which you can do by just doing easy_install gdata. You also need to register for an API key here: http://code.google.com/apis/youtube/dashboard/ The only good getting started guide I could find online was: http://code.google.com/apis/youtube/1.0/developers_guide_python.html#GettingStarted Your first code probably should look something like this (pieced together from the link above): import gdata.youtube import gdata.youtube.service yt_service = gdata.youtube.service.YouTubeService() # The YouTube API does not currently support HTTPS/SSL access. yt_service.ssl = False yt_service.developer_key = 'ABCxyz123...' yt_service.client_id = 'My-Client_id' It seems that you can just pick whatever you want for the client id since its just for debugging and identifying for your own purposes.
Charlie Cheever at Quora Visit the source
Other answers
You can use Python's urllib library to make a call to Youtube API by using an appropriate url. You can get the response back in JSON format and then parse this JSON data to get information regarding a video. You also require an API key. An example code is given below: import urllib import json url = "https://gdata.youtube.com/feeds/api/videos?q=SEARCH_QUERY&key=YOUR_API_KEY&orderby=viewCount&max-results=50&v=2&alt=json" feed = urllib.urlopen(url) feed = feed.read() feed_json = json.loads(feed) for feed in feed_json['feed']['entry']: Video_title = feed['title']['$t'] print Video_title
Akshit Chhabra
this one uses "import requests": http://www.pythonforbeginners.com/python-on-the-web/using-the-youtube-api/ # Import the modules import requests import json # Make it a bit prettier.. print "-" * 30 print "This will show the Most Popular Videos on YouTube" print "-" * 30 # Get the feed r = requests.get("Page on Youtube") r.text # Convert it to a Python dictionary data = json.loads(r.text) # Loop through the result. for item in data['data']['items']: print "Video Title: %s" % (item['title']) print "Video Category: %s" % (item['category']) print "Video ID: %s" % (item['id']) print "Video Rating: %f" % (item['rating']) print "Embed URL: %s" % (item['player']['default']) print
Paul Amerigo Pajo
Nanda Kishore
Related Q & A:
- How can I use SSL with django?Best solution by Stack Overflow
- How can I use XMP in Sharepoint metadata?Best solution by Stack Overflow
- How can I use mongo-sync?Best solution by github.com
- How can I use real time social data from Datasift and perform real time analytics on it?Best solution by Quora
- How can I make a fan video on Youtube?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.