Using the YouTube API to Embed Video in an App
The YouTube Android Player API enables you to incorporate video playback functionality into your Android applications. The API allows you to load and play YouTube videos (and playlists) and to customize and control the video playback experience.
Before using the Android YouTube API, you need to register your application, including your digitally signed .apk file’s public certificate in the Google Developers Console. To register the application, follow these steps.
- Go to the: Google Developers Console
- Create a new project OR use a project you created earlier in the Firebase Console.
- In the sidebar on the left, make sure that Library is selected. On the right panel, select the YouTube Data API and Enable it on the page that follows.
- In the sidebar on the left, select Credentials. For credentials, the API supports OAuth 2.0, the use of an API key and of a Service account. We’ll use the API key option.
- Select API key from the Create Credentials drop down menu. A popup will appear with the value of your YouTube API key.
Note:
The popup window that displays the API key has a Restrict Key button that you can use to restrict the key from unauthorized use. In this tutorial, we won’t restrict the key, but for an app that you plan to push to production, you should definitely restrict access to it. Key restriction lets you specify which websites, IP addresses or apps can use this key. This can help prevent unauthorized use and quota theft.