Youtube Data API | Set-2
Prerequisite: Youtube Data API | Set-1
In the previous article we have discussed first two variants of search method. Now let’s discuss the remaining three- Search Live Events, Search Related Videos and Search My Videos.
Search by Live Events:
Given example retrieves top 5 live broadcasts associated with the query string Python Programming.
type parameter must be set to the value video only.
eventType parameter can take any value from given set of values- completed (this will include only completed broadcasts), live (this will include only active broadcasts), upcoming (this will include only upcoming broadcasts).
Search by Related To video: This will help to retrieve videos related to the video specified by the Video Id in the parameter list.
type parameter can only take value video.
Search My Videos: This example search for the videos matching with keyword “Geeksforgeeks” in authorized user’s account.
forMine parameter indicates that the search should be done within the authorized user’s account.
type parameter must also be set to video. Since this method requires user’s authentication so we will be creating
OAuth type of credential for this example. Follow the steps below to generate a Client Id and a Secret Key.
- Go to Google Google Developers Console and Click on Sign In in the upper rightmost corner of the page. Sign In using the credentials of the valid Google Account. If you don’t have a google account, setup a account first and then use the details to Sign In on the Google Developers Homepage.
- Now navigate to the Developer Dashboard and create a new Project.
- Click on Enable API option.
- In the search field, search for Youtube Data API and select the Youtube Data API option that comes in the drop down list.
- You will be redirected to a screen that says information about the Youtube Data API, along with two options : ENABLE and TRY API.
- Click on ENABLE option to get started 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 the Save button.
- In the Credentials tab, select the Create credentials drop-down list, and choose OAuth Client Id. OAuth is generally used where authorization is required like in the case of retrieving liked videos of a user.
- Select the application type Other, enter the name “YouTube Data API Myvideos”, and click the Create button.
- Click OK.
- Click on 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 the working directory.
Install additional libraries using the pip command:
pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2
While executing the code, it will ask for the authorization code. For getting the code you need to follow the link mentioned in the command prompt screen above the line: Enter the Authorization code.
Now follow the link and copy paste the authorization code that you will get by granting the permission.
Since we don’t have any uploaded videos in this account, so the total results value is 0. Output screen looks like this:
Please refer to the Youtube Data API Documentation(search.list()) for the complete list of parameters that are possible.
Please Login to comment...