Before proceeding further, first see how to get a list of valid Video Categories, to determine in which category to put a video. For the example we have used the “IN” value for the
regionCode parameter. You can use any other value. Only categoryId’s that have
assignable parameter as value “True” can be used in the video insertion or updation.
Let’s discuss how to insert a video in authorized user’s account youtube account.
Find Valid Video Categories:
Since inserting a video in authorized user’s account requires user’s authorization 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 an 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.jsonand move it to the working directory.
Install additional libraries using the
pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2
We have downloaded a sample video- Learn ABC to show how upload works. The id, snippet.title and snippet.categoryId are the mandatory properties, all other are optional.
Insert a video: This example shows how to upload a video to the authorized user’s account. Video upload is governed by following constraints:
- File can take maximum size of 128MB
- Acceptable Media MIME Types are only video/*, application/octet-stream
When 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.
Now as you can see from used account, it show the video is uploaded.
- Youtube Data API for handling videos | Set-2
- Youtube Data API for handling videos | Set-4
- Youtube Data API for handling videos | Set-1
- Youtube Data API for handling videos | Set-5
- HTML | Adding Youtube videos
- Is downloading YouTube videos legal?
- Pytube | Python library to download youtube videos
- Youtube Data API | Set-1
- Youtube Data API | Set-2
- Youtube Data API Subscription | Set-2
- Youtube Data API Playlist | Set-3
- Youtube Data API Subscription | Set-3
- Youtube Data API Subscription | Set-1
- Youtube Data API Playlist | Set-4
- Youtube Data API Playlist | Set-2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.