Course project for EC601 at BU.
Our whole project codes are in folder zhduan
. There are two ways you can reuse our codes.
- Run our website on your own computer.
- Use our YouTube API library.
We use Django as our server framework. You can try our website on your localhost simply by the following steps.
-
Make sure you have a python 3.x
-
Install Django and Python Social Auth of Django
pip install Django
pip install social-auth-app-django
- Download our codes, open terminal in
/zhduan
, then
python manage.py runserver 0:80
or
python manage.py runserver
-
You are all set! Open your browser and enter
localhost
(python manage.py runserver 0:80) orlocalhost:8000
(python manage.py runserver), then you should see a UI of the website. -
Open
/zhduan/youtube/ytbAPI.py
, enter your Google API Key atline 7
. For how to get a Google API Key, you can read the official doc, or create API key here. -
Now you can access most functions of the website on your localhost, except ones need OAuth 2 (for how to use Google OAuth 2, please see our
docs/Google OAuth 2.md
).
If you just want to try our YouTube API instead of the whole project, take the following steps. (Make sure you have Python 3.x)
-
/zhduan/youtube/ytbAPI.py
is a simple API to connect YouTube/Google./zhduan/youtube/youtube_lib.py
contains many functions which useytbAPI.py
to connect YouTube/Google. There are build-in comments in these files, and they are pretty ez to read. -
Install urllib3
pip install urllib3
-
Download
/zhduan/youtube/ytbAPI.py
. Put it in the same folder with your own codes. Enter your Google API Key atline 7
. For how to get a Google API Key, you can read the official doc, or create API key here. -
Import our library
from .ytbAPI import ytbAPI
-
You are all set!
-
Here is an example of getting top 10 viewed video in YouTube in the history. There are more in
youtube_lib.py
.
from .ytbAPI import ytbAPI
ytb0 = ytbAPI()
ytb0.scope('search')
ytb0.part('snippet')
ytb0.maxResults(10)
ytb0.order('viewCount')
ytb0.type('video')
ytb0.key()
response = ytb0.GET()
for i in response['items']:
print(i['snippet']['title'])