In this article, we will be discussing video rating and getting a video rating.
The examples in this article will require user authentication. So, first we will create the OAuth Credential and install additional libraries.
Follow the steps below to generate a Client ID and Secret.
- Go to developer console Google Google and click Sign In in the top right corner of the page. Sign in with your valid Google account credentials. If you do not have a Google account, first set up an account and then use your login details on the Google Developers homepage.
- Now navigate to developer toolbars and create a new project.
- Click on the Enable API option.
- In the search box, search for Youtube Data API and select the Youtube Data API option that appears in the dropdown.
- You will be redirected to the Youtube Data API information screen along with two options: ENABLE and TRY API .
- Click on the ENABLE option to start working with the API.
- In the sidebar, under APIs & Services, select Credentials .
- At the top of the page, select the OAuth consent screen tab. Select an email address, enter a product name if not already set, and click Save.
- On the Credentials tab, select the Create Credentials drop-down list and select OAuth Client ID. OAuth is typically used where authorization is required, such as retrieving a user’s favorite videos.
- Select the application type Other, enter the name YouTube Myvideos Data API, click the Create button, and click OK ".
- Click the Download button to the right of the client ID to download the JSON file.
- Save and rename the file as
client_secret.json
and move it to working directory.
Install additional libraries using pip :
pip install --upgrade google-auth google-auth-oauthlib google -auth-httplib2
Code for video rating. this example shows you how to rate a video. In this example, we rate a video with a like. You have three options: Like, Dislike, and No (means remove any type of like / dislike rating from the video).
|
Exit:
When you execute the code, you will be prompted for an authorization code. To get the code, you must follow the link indicated on the command line screen above the line: Enter the authorization code.
Now follow the link and copy and paste the authorization code that you will receive by granting permission.
From the images of my Youtube account, you can see that there is an addition to the list of related videos.
Code for getRating: in This example shows how to get an authorized user rating for a video list in the options list.
|
Exit :
When you execute code, you will be prompted to enter an authorization code. To get the code, you must follow the link indicated on the command line screen above the line: Enter the authorization code.
Now follow the link and copy and paste the authorization code that you will receive by granting permission.
As you can see from the output, one of the videos is rated as similar and the other two are not rated.
Links :
- https://developers.google.com/youtube/v3/docs/videos/rate
- https://developers.google.com/youtube/v3/docs/videos/getRating