{"id":5162,"date":"2023-05-15T12:25:52","date_gmt":"2023-05-15T12:25:52","guid":{"rendered":"https:\/\/unremot.com\/blog\/?p=5162"},"modified":"2023-05-16T11:49:15","modified_gmt":"2023-05-16T11:49:15","slug":"how-to-use-youtube-api","status":"publish","type":"post","link":"https:\/\/unremot.com\/blog\/how-to-use-youtube-api\/","title":{"rendered":"How To Use YouTube API &#8211; A Step-By-Step Guide To Integrate YouTube API And Full Documentation List"},"content":{"rendered":"<p>Let us understand how to use YouTube API &#8211; A Step-By-Step guide to Integrate YouTube API and full documentation list.<\/p>\n\n<h2><b>Overview of YouTube API<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The YouTube API is an application program interface that enables you to curate a playlist, and embedded videos, and provides other YouTube features on your website. Thanks to the API organizations do not have to build new code from scratch and can offer advanced video-sharing services on their website or app.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Google YouTube API like other APIS (application program interface) simplifies programming by avoiding the tedious task of writing extensive lines of code every time the user wants to access data. Coders can use preset functions and protocols when selecting YouTube videos for their websites.<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read: <\/strong><a href=\"https:\/\/hbr.org\/2013\/08\/move-beyond-enterprise-it-to-a\" target=\"_blank\" rel=\"noopener\">Move Beyond Enterprise IT to an API Strategy<\/a><\/p>\n<h2><b>YouTube API scopes, types, and functionalities<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Like any other API, the YouTube Video API has simplified coding by eliminating the need to write multiple lines of code each time the user needs to access data. Instead, they use predefined functions and protocols to curate YouTube videos on a website.\u00a0 YouTube API has a range of functionalities and features that make it useful for businesses and developers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Compared to standalone YouTube embed codes, YouTube API allows you to access YouTube\u2019s data in a more thorough and scalable manner. With the YouTube API, you may access complete playlists, user uploads, and even search results.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To allow viewers to upload videos, manage channel subscriptions directly from the website or app, and add YouTube functionality to your website.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The common functionalities of YouTube API services are listed below.<\/span><\/p>\n<table style=\"height: 1046px;\" width=\"1039\">\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><strong>YouTube<br \/>\nResources<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Example Http<br \/>\nRequest<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nSearch<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Get\/Search\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Retrieves a range of search results based on<br \/>\nqueries<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nPlaylist\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">DELETE\/Playlist\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Delete a playlist<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nVideos<\/span><\/td>\n<td><span style=\"font-weight: 400;\">POST\/Videos<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Uploads videos to YouTube from your website or app<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\ncomments<\/span><\/td>\n<td><span style=\"font-weight: 400;\">POST\/comments\/markAsSpam<\/span><\/td>\n<td><span style=\"font-weight: 400;\">You can flag one or more comments as spam.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nChannels<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GET\/Channel<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Retrieves a channel\u2019s videos or playlists (or any other resource, such as comments)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube Subscription<\/span><\/td>\n<td><span style=\"font-weight: 400;\">POST\/subscription<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Adds a subscriber to an authenticated user\u2019s<br \/>\nchannel.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nMembers<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GET\/members<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Retrieves a list of members for a channel that has given you authorization.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nCaption<\/span><\/td>\n<td><span style=\"font-weight: 400;\">PUT\/Captions<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Updates a caption track (you can upload a new<br \/>\nfile or change it to a draft.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nChannel<br \/>\nSections<\/span><\/td>\n<td><span style=\"font-weight: 400;\">POST\/<br \/>\nchannelSections<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Add a section of featured videos, for example, to an authenticated user\u2019s channel<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">YouTube<br \/>\nWatermarks<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Post\/WaterMarks<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Remove watermark image associated with a<br \/>\nchannel<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><\/h2>\n<h2><b>How to use YouTube API &#8211; 7 step integration guide<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In this section, we focus on how to use YouTube API integration. It is 7 steps simple API integration YouTube.\u00a0<\/span><\/p>\n<p><strong>Step1: Log in to Google Developer Console<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Create a Google account and use the credentials to log in to Google Developers Console.<\/span><\/p>\n<p><strong>Step2: Create a new project<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">When you first log in you will see an empty dashboard. On the upper right corner of your screen, click on\u00a0<\/span><i><span style=\"font-weight: 400;\">Create Project.\u00a0 <\/span><\/i><span style=\"font-weight: 400;\">You will be directed to a screen where you can add a project name, and select organization and URL from the dropdown box. After you create the project, everything you do moving forward including the API Key will be exclusively for the project. If you are working on multiple projects concurrently ensure the correct project is selected.\u00a0<\/span><\/p>\n<p><strong>Step3: On a new project dashboard, explore and enable API<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">You will now be taken to a brand-new dashboard with different cards like Project name and resources. Find the\u00a0<\/span><i><span style=\"font-weight: 400;\">Getting Started<\/span><\/i><span style=\"font-weight: 400;\">\u00a0card and click on\u00a0<\/span><i><span style=\"font-weight: 400;\">Explore and Enable APIs.\u00a0<\/span><\/i><span style=\"font-weight: 400;\">Alternatively, you can navigate to the APIs and services &gt; library.<\/span><\/p>\n<p><strong>Step4: In the library, navigate to YouTube Data API v3 under YouTube APIs<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">The YouTube API console is divided into sections \u2013 Navigate to the YouTube APIs and select\u00a0<\/span><i><span style=\"font-weight: 400;\">YouTube Data API v3\u00a0<\/span><\/i><span style=\"font-weight: 400;\">or you can search for\u00a0<\/span><i><span style=\"font-weight: 400;\">YouTube Data API\u00a0<\/span><\/i><span style=\"font-weight: 400;\">in the search console.<\/span><\/p>\n<p><strong>Step5: Enable APIs<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Once you arrive at the YouTube Data API page, click the\u00a0<\/span><i><span style=\"font-weight: 400;\">Enable\u00a0<\/span><\/i><span style=\"font-weight: 400;\">button.<\/span><\/p>\n<p><strong>Step6: Create a credential<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">After clicking the Enable button you will be able to view the overview page. Click<\/span><i><span style=\"font-weight: 400;\">\u00a0Create Credentials\u00a0<\/span><\/i><span style=\"font-weight: 400;\">in the top right-hand corner. <\/span><span style=\"font-weight: 400;\">In the Credentials window, select\u00a0<\/span><i><span style=\"font-weight: 400;\">YouTube Data API v3\u00a0<\/span><\/i><span style=\"font-weight: 400;\">from the dropdown menu, WebServer (Tomcat, Node.js), and check the <\/span><i><span style=\"font-weight: 400;\">Public data<\/span><\/i><span style=\"font-weight: 400;\">\u00a0in the third option.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Select &#8220;What credentials do I need?\u201d You can now get the YouTube API key. Click\u00a0<\/span><i><span style=\"font-weight: 400;\">\u00a0Done\u00a0<\/span><\/i><\/p>\n<p><strong>Step7: A screen with the API key will appear<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Done! Congratulations you now have the API key. You need to save credentials.<\/span><\/p>\n<h2><b>YouTube API documentation references<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The YouTube API is a powerful tool for developers to interact with the YouTube platform and get access to the wealth of information available on YouTube. The API allows developers to retrieve data, upload videos, manage playlists and much more.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can access <a href=\"https:\/\/developers.google.com\/youtube\/v3\/docs\" target=\"_blank\" rel=\"noopener\">YouTube API documentation<\/a> on the YouTube Developers website. Each API endpoint is described in depth in the documentation, along with the parameters that can be supplied and the format of the answer. <\/span><span style=\"font-weight: 400;\">YouTube offers sample code and client libraries many programming languages in addition to the API documentation, making it simple for developers to get started with the API right away.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For programmers wishing to use the YouTube API, the following resources may be helpful:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/youtube-data-api.readthedocs.io\/en\/latest\/youtube_api.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">YouTubecalculator API documentation<\/span><\/a><span style=\"font-weight: 400;\"> and is provided by YouTube. It is a comprehensive documentation covering everything from authentication to API endpoints and response formats. The documentation is easy to navigate.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">\u00a0<\/span><a href=\"https:\/\/developers.google.com\/youtube\/v3\/docs\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">YouTube API reference Guide<\/span><\/a><span style=\"font-weight: 400;\"> provides an overview of the API&#8217;s functionality, including authentication, quota usage, error handling, and recommended API usage procedures.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/developers.google.com\/apis-explorer\/#p\/youtube\/v3\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">YouTube Tools<\/span><\/a><span style=\"font-weight: 400;\"> lets you test authorized and unauthorized requests. The Quota calculator show how usage impacts your quota usage.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">YouTube Data forum is a community forum where developers can ask questions and get help from other developers who are using the YouTube API.<\/span><\/li>\n<\/ul>\n<h2><b>YouTube API examples<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Developers may access and engage with YouTube&#8217;s enormous library of videos, channels, and playlists thanks to the YouTube API. The creation of unique applications, automated video uploads, and data collection for analysis are all possible with this potent tool. In this section, we focus on different YouTube API examples in different languages.\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/how-to-use-spotify-api\/\">How to use Spotify API; a step-by-step integration guide and full documentation list<\/a><\/strong><\/p>\n<h3><b>How to use YouTube API Python?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Prerequisites you need Python 2.7 or Python 3.5, pip package management tool, and Google API Client Library for Python. <\/span><span style=\"font-weight: 400;\">This simple guide explains how to use <a href=\"https:\/\/developers.google.com\/youtube\/v3\/quickstart\/python\" target=\"_blank\" rel=\"noopener\">YouTube API Python<\/a>,\u00a0<\/span><\/p>\n<p><strong>Step1: Set up your project credentials<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Start by setting up YouTube API and download your credentials.json in the current direct of your notebook\/Python file.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Use the APIs Explorer widget in the side panel to obtain sample code for retrieving the information about GoogleDevelopers YouTube Channel. This call does not need user authorization or other specialized rights from the user running the sample; it simply utilizes an API key to identify your application.<\/span> <span style=\"font-weight: 400;\">Click the code symbol for the first listing to open and populate the fullscreen APIs Explorer.<\/span><\/li>\n<\/ul>\n<p><strong>Step2: Set up and run the sample\u00a0<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">You will be able to see the following information on the left side of the fullscreen API explorer.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">List of parameters the method support below the request parameters header. The part and the id parameter values should be set. The part and id parameter value should be set. The parameter <\/span><span style=\"font-weight: 400;\">value,\u00a0UC_x5XG1OV2P6uZZ5FSM9Ttw, is the ID for the GoogleDevelopers YouTube channel<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">You will be able to see credentials\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Below the parameters, there is a section named\u00a0<\/span><b>Credentials<\/b><span style=\"font-weight: 400;\">. The pulldown menu in that section should display the value\u00a0<\/span><b>API key<\/b><span style=\"font-weight: 400;\">. The APIs Explorer uses demo credentials by default to make it easier to get started. But you&#8217;ll use your own API key to run the sample locally.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">On the right side of the fullscreen API explorer you can see tabs with code samples in several languages. Select the Python tab.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Copy the code samples <\/span><span style=\"font-weight: 400;\">and save it in a file named\u00a0example.py.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In the sample that you downloaded, find the\u00a0YOUR_API_KEY\u00a0string and replace it with API Key for your application.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Run the sample from the command line. In your working directory, run: <\/span><span style=\"font-weight: 400;\">python example.py<\/span><\/li>\n<li><span style=\"font-weight: 400;\">The sample should execute the request and print the response to\u00a0STDOUT.<\/span><\/li>\n<\/ul>\n<p><strong>Step 3: Run authorized requests<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">You can now modify your code sample so that it collects information from your YouTube channel instead\u00a0 GoogleDevelopers YouTube channel. You need to authorize this request.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Go back to the documentation for the API&#8217;s\u00a0<\/span><span style=\"font-weight: 400;\">channels.list<\/span><span style=\"font-weight: 400;\">\u00a0method.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the &#8220;Common use cases&#8221; section, click the code symbol for the third listing in the table. That use case is to call the\u00a0<\/span><span style=\"font-weight: 400;\">list<\/span><span style=\"font-weight: 400;\">\u00a0method for &#8220;my channel.&#8221;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">On the left side of the fullscreen APIs Explorer look for the list of <\/span><span style=\"font-weight: 400;\">parameters <\/span><span style=\"font-weight: 400;\">followed by the\u00a0<\/span>Credentials<span style=\"font-weight: 400;\">\u00a0section. However, there are two changes from the example where you retrieved information about the GoogleDevelopers channel:<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the parameters section, instead of the\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">\u00a0parameter value being set, the\u00a0<\/span><span style=\"font-weight: 400;\">mine<\/span><span style=\"font-weight: 400;\">\u00a0parameter value should be set to\u00a0<\/span><span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">. This instructs the API server to retrieve information about the currently authenticated user&#8217;s channel.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In the\u00a0<\/span>Credentials<span style=\"font-weight: 400;\">\u00a0section, the pulldown menu should select the option for\u00a0<\/span>Google OAuth 2.0<span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In addition, if you click the\u00a0<\/span>Show scopes <span style=\"font-weight: 400;\">link, the<\/span><span style=\"font-weight: 400;\">\u00a0scope should be checked.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select the\u00a0<\/span>Python<span style=\"font-weight: 400;\">\u00a0tab, copy the code sample, and save it to\u00a0<\/span><span style=\"font-weight: 400;\">example.py<\/span><span style=\"font-weight: 400;\">. Look for the <\/span><span style=\"font-weight: 400;\">YOUR_CLIENT_SECRET_FILE.json<\/span><span style=\"font-weight: 400;\"> string and replace it with the location of the client secret file you downloaded in step1.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Run the sample from the command line. In your working directory, run: <\/span>python example.py<\/li>\n<li><span style=\"font-weight: 400;\">Copy the URL from the console and open it in your browser.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In case you have not logged into your Google account, you will be prompted to log in. If you are logged into multiple Google accounts, you will be asked to select one account to use for the authorization.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click the button to grant your application access to the scopes specified in your code sample.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Copy the auth code from the browser and paste it into your terminal. You can then close the browser tab used for the auth flow. The API response should again be printed to\u00a0<\/span><span style=\"font-weight: 400;\">STDOUT<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/what-to-look-for-in-a-geolocation-api\/\">What to Look for in a Geolocation API<\/a><\/strong><\/p>\n<h2><b>How to use YouTube JavaScript API tutorial<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">If you want to explore YouTube JavaScript API and learn to use it, the best way would be via a project.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Step1:<\/strong> <strong>The first step is to go to the Google Cloud console and create your project.<\/strong> <\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have already explained how you can generate the API key in the preceding section.\u00a0<\/span><\/p>\n<p><strong>Step2: Set up and run the sample<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">To acquire examples of code to retrieve data from the GoogleDevelopers YouTube channel, use the APIs Explorer widget on the side panel. This call does not need user authorization or other specialized rights from the user running the sample; it simply utilizes an API key to identify your application.<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Open the <a href=\"https:\/\/developers.google.com\/youtube\/v3\/docs\/channels\/list\" target=\"_blank\" rel=\"noopener\">channels.list<\/a> method&#8217;s documentation in the API. The &#8220;Common use cases&#8221; part of that page includes a table that lists various typical applications of the technology. Results by channel ID are listed in the table&#8217;s first row.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">For the fullscreen APIs Ex, open it by clicking the code symbol for the first listing.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Open the channels.list method&#8217;s documentation in the API.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">The &#8220;Common use cases&#8221; part of that page includes a table that lists various typical applications of the technology. Results by channel ID are listed in the table&#8217;s first row.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">For the fullscreen APIs Examples, open it by clicking the code symbol for the first listing.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">You can see the following information on the left-side of the fullscreen API explorer \u2013\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Request parameter header contains a list of parameters that the method supports. The values for the part and id parameters should be set. The ID for the GoogleDevelopers YouTube channel is given below:<\/span> <span style=\"font-weight: 400;\">UC_x5XG1OV2P6uZZ5FSM9Ttw<\/span><span style=\"font-weight: 400;\">, which is the value for the id parameter.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Credentials is a part that is located below the parameters. The value API key ought to appear in the pulldown option in that area. To make things simpler to use when getting started, the APIs Explorer utilizes demo credentials by default. But to run the sample locally, you&#8217;ll need your own API key.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">On the right-side of the fullscreen API explorer shows tabs with code samples in the different languages you can select JavaScript from the list.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Copy the code sample and save it as example.html.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Look for <\/span><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">YOUR_API_KEY<\/span><span style=\"font-weight: 400;\">\u00a0string in the example and replace that with the API key that you created in step 1.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Start the web server using the following command from your working directory:<\/span><\/li>\n<li><span style=\"font-weight: 400;\">python -m http.server 8000<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Open the example.html file in your browser and the browser\u2019s developer tools, such as the \u201cDeveloper Tools\u201d in the Chrome browser.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click the <\/span><i><span style=\"font-weight: 400;\">load <\/span><\/i><span style=\"font-weight: 400;\">button to load the Google APIs Client Library for JavaScript. After you click the button, the developer console shows a note indicating the GAPI client is loaded.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click on the <\/span><i><span style=\"font-weight: 400;\">execute <\/span><\/i><span style=\"font-weight: 400;\">button to send API request. The developer\u2019s console should then display the API response.\u00a0<\/span><\/li>\n<\/ul>\n<p><strong>Step3: Run an authorized request<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">We will now modify your code sample so that it collects information from your YouTube Channel rather than GoogleDeveloper\u2019s YouTube channel. User consent is required for the request.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Return to the channels.list method of the API&#8217;s documentation.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click the code icon next to the third listing in the table under &#8220;Common use cases&#8221; in the section. To use case one, invoke the list method for &#8220;my channel.&#8221;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click the code icon next to the third listing in the table under &#8220;Common use cases&#8221; in the section. To use case one, invoke the list method for &#8220;my channel.&#8221;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">A list of parameters is displayed on the left side of the full-screen APIs Explorer, followed by an area for credentials. But there are two differences from the case where you got data via the GoogleDevelopers channel<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The mine parameter value should be set to true in the parameters section rather than the id parameter value. This tells the API server to get data on the channel of the user who is presently logged in.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The pulldown menu in the Credentials area needs to be set to Google OAuth 2.0.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Additionally, you should check the <\/span><span style=\"font-weight: 400;\"> scope if you click the Show scopes link<\/span><\/p>\n<h2><b>How to use YouTube API Node Js?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In this section, we focus on learning how to use YouTube API Node. You first need to create new project and get the API key for the project. You now need to generate a node application. Now create our package.json <\/span><\/p>\n<p><span style=\"font-weight: 400;\">npm init<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now install express. Express is the most popular and small framework for Node and it\u00a0 provides us with routes and a simple means of parsing query parameters.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">npm install express<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We create an express application to start it<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 const express = require(&#8220;express&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 const app = express();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 app.get(&#8220;\/&#8221;, (req, res) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 res.send(&#8220;Hello World!&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 app.listen(port, () =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0console.log(<\/span><span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">App listening at http:\/\/localhost:${port}`);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To start an application we write in the console the below <\/span><\/p>\n<p><span style=\"font-weight: 400;\">node server.js<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Confirm the request is working in the browser.\u00a0 Our next step is to create a new URL where we can provide some search strings and get date from YouTube API.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">app.get(<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">\/search<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">, async (req, res, next) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const searchQuery = req.query.search_query;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0res.send(searchQuery);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The search URL is working because URL is working because we used express to read query parameters. It is time to use API of YouTube. If you want to get <\/span><span style=\"font-weight: 400;\">the list of videos like in search of YouTube here is the request that we need for this.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As you can see ou<\/span><span style=\"font-weight: 400;\">r search URL is working and because we used express we get out of the box possibility to read query parameters.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now it&#8217;s time to use API of youTube. As we want to get the list of videos like in search of YouTube here is the <a href=\"https:\/\/www.googleapis.com\/youtube\/v3\/search?key=apiKey&amp;type=video&amp;part=snippet&amp;q=foo\" target=\"_blank\" rel=\"noopener\">request<\/a> that we need for this.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can see v3 api here and we offer various stuff. The API key is critical or we will see a 403 error without it. The q parameter comes next. This is the search term we use when entering a YouTube search. In order to receive more fields in the response, such as the title, description, tags, and channel id, we additionally want to provide part=snippet. Since there are many more video types, including channels, playlists, and many more, we also wish to filter our data by video type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">npm install axios<\/span><\/p>\n<p><span style=\"font-weight: 400;\">use async await notation to make code easier to read and support<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const axios = require(<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">axios<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const apiKey = <\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">AIzaSyDh4lSGdVGOnOg9oEvLTeLeCvl1eH5UMb0<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const apiUrl = <\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">https:\/\/www.googleapis.com\/youtube\/v3<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">app.get(<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">\/search<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><span style=\"font-weight: 400;\">, async (req, res, next) =&gt; {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><b>try<\/b><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const searchQuery = req.query.search_query;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const url = <\/span><span style=\"font-weight: 400;\">`<\/span><b>$<\/b><span style=\"font-weight: 400;\">{apiUrl}\/search?key=<\/span><b>$<\/b><span style=\"font-weight: 400;\">{apiKey}&amp;type=video&amp;part=snippet&amp;q=<\/span><b>$<\/b><span style=\"font-weight: 400;\">{searchQuery}<\/span><span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const response = await axios.get(url);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0const titles = response.data.items.map((item) =&gt; item.snippet.title);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0res.send(titles);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0} <\/span><b>catch<\/b><span style=\"font-weight: 400;\"> (err) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0next(err);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So here I stored API key and API URL in additional properties so we can reuse them in other requests later. we also prepare the correct URL with params and call axios.get with await. Inside response we loop through all items to get titles of each element.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We also wrapped our code in try catch block so we can react on errors. The easiest way to handle errors is just to propagate it to Express framework by using next. <\/span><span style=\"font-weight: 400;\">As you can see in browser our code is working and we get our list of video titles in API.<\/span><\/p>\n<h2><b>How to use c# YouTube API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Using C# YouTube API is quite intuitive.\u00a0<\/span><\/p>\n<p><strong>Step1: Create a Google API Console Project<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Go to the Google cloud console to create a project using the steps outlined in the previous section. You will get an API on the successful creation of the project.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Step2:<\/strong> Create a new C# console application in Visual Studio You can create a new C# console application in Visual Studio by selecting &#8220;File&#8221; -&gt; &#8220;New&#8221; -&gt; &#8220;Project&#8221; and then selecting &#8220;Console App (.NET Framework)&#8221; under the C# section.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Step3: Install the Google API client library for .net<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">To access the YouTube API for C# application, you need install Google\u00a0 API client library for .NET.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Go to the Package Manage Console and enter the following command<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Install<\/span><span style=\"font-weight: 400;\">&#8211;<\/span><span style=\"font-weight: 400;\">Package Google<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Apis<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">YouTube<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">v3<\/span><\/p>\n<p><strong>Step4 : Include namesspace in the class file<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">using<\/span> <span style=\"font-weight: 400;\">Google.Apis.Services;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">using<\/span> <span style=\"font-weight: 400;\">Google.Apis.YouTube.v3;<\/span><\/p>\n<p><strong>Step5: Add following methods to your class file<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Find the Given method and replace it your API key.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">private<\/span> <span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">Task<\/span> <span style=\"font-weight: 400;\">GetYouTubeVideos()<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">var<\/span><span style=\"font-weight: 400;\"> youtubeService <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">YouTubeService(new<\/span> <span style=\"font-weight: 400;\">BaseClientService.Initializer()<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ApiKey <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">&#8220;REPLACE_ME&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ApplicationName <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">this.GetType().ToString()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">var<\/span><span style=\"font-weight: 400;\"> searchListRequest <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> youtubeService<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Search<\/span><span style=\"font-weight: 400;\">.List(&#8220;snippet&#8221;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0searchListRequest<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Q <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">&#8220;My Videos&#8221;;<\/span> <span style=\"font-weight: 400;\">\/\/ Replace with your search term.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0searchListRequest<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">MaxResults <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">50;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\/\/ Call the search.list method to retrieve results matching the specified query term.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">var<\/span><span style=\"font-weight: 400;\"> searchListResponse <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span><span style=\"font-weight: 400;\"> searchListRequest<\/span><span style=\"font-weight: 400;\">.ExecuteAsync();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">List &lt; string &gt;<\/span><span style=\"font-weight: 400;\"> videos <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">List &lt; string &gt;<\/span> <span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">List &lt; string &gt;<\/span><span style=\"font-weight: 400;\"> channels <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">List &lt; string &gt;<\/span> <span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">List &lt; string &gt;<\/span><span style=\"font-weight: 400;\"> playlists <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">List &lt; string &gt;<\/span> <span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\/\/ Add each result to the appropriate list, and then display the lists of<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">\/\/ matching videos, channels, and playlists.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">foreach(var<\/span><span style=\"font-weight: 400;\"> searchResult <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> searchListResponse<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Items<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">switch<\/span> <span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Id<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Kind<\/span><span style=\"font-weight: 400;\">)<\/span> <span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">&#8220;youtube#video&#8221;:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0videos<\/span><span style=\"font-weight: 400;\">.Add(string.Format(&#8220;{0} ({1})&#8221;,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Snippet<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Title<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Id<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">VideoId<\/span><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">break;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">&#8220;youtube#channel&#8221;:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channels<\/span><span style=\"font-weight: 400;\">.Add(string.Format(&#8220;{0} ({1})&#8221;,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Snippet<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Title<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Id<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">ChannelId<\/span><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">break;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">case<\/span> <span style=\"font-weight: 400;\">&#8220;youtube#playlist&#8221;:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0playlists<\/span><span style=\"font-weight: 400;\">.Add(string.Format(&#8220;{0} ({1})&#8221;,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Snippet<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Title<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\"> searchResult<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">Id<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">PlaylistId<\/span><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">break;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Console<\/span><span style=\"font-weight: 400;\">.WriteLine(string.Format(&#8220;Videos:\\n{0}\\n&#8221;,<\/span> <span style=\"font-weight: 400;\">string.Join(&#8220;\\n&#8221;,<\/span><span style=\"font-weight: 400;\"> videos<\/span><span style=\"font-weight: 400;\">)));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Console<\/span><span style=\"font-weight: 400;\">.WriteLine(string.Format(&#8220;Channels:\\n{0}\\n&#8221;,<\/span> <span style=\"font-weight: 400;\">string.Join(&#8220;\\n&#8221;,<\/span><span style=\"font-weight: 400;\"> channels<\/span><span style=\"font-weight: 400;\">)));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0Console<\/span><span style=\"font-weight: 400;\">.WriteLine(string.Format(&#8220;Playlists:\\n{0}\\n&#8221;,<\/span> <span style=\"font-weight: 400;\">string.Join(&#8220;\\n&#8221;,<\/span><span style=\"font-weight: 400;\"> playlists<\/span><span style=\"font-weight: 400;\">)));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The above posted above calls API\u2019s search.list method to obtain search results linked to a specific keyword.<\/span><\/p>\n<p><strong>Step6: Use the following method in your class\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">static<\/span> <span style=\"font-weight: 400;\">void<\/span> <span style=\"font-weight: 400;\">Main(string[]<\/span><span style=\"font-weight: 400;\"> args<\/span><span style=\"font-weight: 400;\">)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">Program().GetYouTubeVideos().GetAwaiter().GetResult();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Console<\/span><span style=\"font-weight: 400;\">.ReadLine();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can view the basic video details in the console. You can refer to the <\/span><a href=\"https:\/\/developers.google.com\/youtube\/v3\/docs\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">API\u00a0 documents<\/span><\/a><span style=\"font-weight: 400;\"> to get more functionality.\u00a0<\/span><\/p>\n<h2><b>How to use YouTube API php curl?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">There are a few steps you must take in order to access the YouTube API with PHP and cURL:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Activate the YouTube API key and create a Google Cloud Platform project: In the Google Cloud Console, you must create a project and enable the YouTube Data API if you haven&#8217;t previously. The documentation for Google Developers contains more details on how to do this.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To access the YouTube API, you must first obtain API credentials, which consist of a client ID and client secret. The steps in the manual for Google Developers can be used to do this.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Install and enable cURL in your PHP environment: This is a prerequisite. Run this command to see if cURL has been set up.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">php -m | grep curl<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If cURL isn&#8217;t already installed, you can either get it from the cURL website or install it using your package management (such as apt-get, yum, etc.).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Log in using the YouTube API: You&#8217;ll need to use the client ID and client secret you previously got to obtain an access token in order to authenticate with the YouTube API. Here&#8217;s an illustration of how to authenticate in PHP using cURL:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$client_id = &#8216;YOUR_CLIENT_ID&#8217;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$client_secret = &#8216;YOUR_CLIENT_SECRET&#8217;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Set up cURL<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ch = curl_init();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_URL, &#8216;https:\/\/accounts.google.com\/o\/oauth2\/token&#8217;);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_POST, true);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_POSTFIELDS, array(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;grant_type&#8217; =&gt; &#8216;client_credentials&#8217;,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;client_id&#8217; =&gt; $client_id,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;client_secret&#8217; =&gt; $client_secret,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;scope&#8217; =&gt; &#8216;https:\/\/www.googleapis.com\/auth\/youtube.force-ssl&#8217;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Send the request<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$response = curl_exec($ch);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_close($ch);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Decode the response<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$json = json_decode($response, true);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Get the access token<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$access_token = $json[&#8216;access_token&#8217;];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can use an access token to send requests to the YouTube API once you have one. Here&#8217;s a perfect example of how to search for videos using cURL:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$search_term = &#8216;SEARCH_TERM&#8217;;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Set up cURL<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ch = curl_init();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_URL, &#8216;https:\/\/www.googleapis.com\/youtube\/v3\/search?part=snippet&amp;q=&#8217; . urlencode($search_term));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_setopt($ch, CURLOPT_HTTPHEADER, array(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;Authorization: Bearer &#8216; . $access_token,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8216;Accept: application\/json&#8217;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">));<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Send the request<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$response = curl_exec($ch);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">curl_close($ch);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Decode the response<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$json = json_decode($response, true);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\/\/ Loop through the results<\/span><\/p>\n<p><span style=\"font-weight: 400;\">foreach ($json[&#8216;items&#8217;] as $item) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\/\/ Do something with the search results<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read: <a href=\"https:\/\/unremot.com\/blog\/how-to-use-chatgpt-api\/\">How to use ChatGPT API; a step-by-step integration guide and full documentation list<\/a><\/strong><\/p>\n<h2><b>How to use Google YouTube Android API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Prerequisite to use Google YouTube Android API are\u00a0 Android Studio SDK 1.2 or later, Android SDK packages, access to internet on your test device, and Google account.\u00a0<\/span><\/p>\n<p><strong>Step1: Acquire a SHAI fingerprint<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Run the Keytool utility command shown below in a terminal to obtain the SHA1 fingerprint you will need to enable the API.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">keytool -exportcert -alias androiddebugkey -keystore ~\/.android\/debug.keystore -list -v<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Enter \u201candroid\u201d when promoted for a keystore password. The keystore prints prints fingerprint in the shell.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ keytool -exportcert -alias androiddebugkey -keystore ~\/.android\/debug.keystore -list -v<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Enter keystore password: Type &#8220;android&#8221; if using debug.keystore<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Alias name: androiddebugkey<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Creation date: Dec 4, 2014<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Entry type: PrivateKeyEntry<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Certificate chain length: 1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Certificate[1]:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Owner: CN=Android Debug, O=Android, C=US<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Issuer: CN=Android Debug, O=Android, C=US<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Serial number: 503bd581<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Valid from: Mon Aug 27 13:16:01 PDT 2012 until: Wed Aug 20 13:16:01 PDT 2042<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Certificate fingerprints:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">MD5: <\/span><\/p>\n<p><span style=\"font-weight: 400;\">1B:2B:2D:37:E1:CE:06:8B:A0:F0:73:05:3C:A3:63:DD<\/span><\/p>\n<p>SHA1:<\/p>\n<p>D8:AA:43:97:59:EE:C5:95:26:6A:07:EE:1C:37:8E:F4:F0:C8:05:C8<\/p>\n<p><span style=\"font-weight: 400;\">SHA256:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">F3:6F:98:51:9A:DF:C3:15:4E:48:4B:0F:91:E3:3C:6A:A0:97:DC:0A:3F:B2:D2:E1:FE:23:57:F5:EB:AC:13:30<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Signature algorithm name: SHA1withRSA<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Version: 3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Copy the SHAI fingerprint highlighted in the example\u00a0 above.\u00a0<\/span><\/p>\n<p><strong>Step2: Turn on the YouTube Data API<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To automatically enable the API, use this <\/span><a href=\"https:\/\/console.cloud.google.com\/projectselector2\/apis\/enableflow?apiid=youtube&amp;pli=1&amp;supportedpurview=project\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">wizard<\/span><\/a><span style=\"font-weight: 400;\"> to create or choose a project in the Google Developers Console. Continue by clicking, then select Credentials.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click the Cancel option located on the Create Credentials page.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Choose the OAuth consent screen tab from the menu at the top of the page. Once you&#8217;ve chosen an email address and, if necessary, a product name, click the Save button.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click the <\/span><b><i>Create <\/i><\/b><span style=\"font-weight: 400;\">credentials button while selecting OAuth client ID on the Credentials tab.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Choose the Android application category.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the Signing-certificate fingerprint field, paste the SHA1 fingerprint from Step1<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Enter com.example in the field marked &#8220;Package name&#8221;.quickstart.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Select &#8220;Create&#8221; from the menu.<\/span><\/li>\n<\/ul>\n<p><strong>Step3: Create an Android Project<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Open Android Studio and start a new Android Studio Project.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the New Project screen and name the application \u201cQuickStart\u201d<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Specify &#8220;example.com&#8221; as the Company Domain, and make sure the package name that is generated automatically corresponds to the one you supplied in the Developer Console in Step2. Choose Next.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Check the Phone and Tablet checkbox and select &#8220;API 14: Android 4.0 (IceCreamSandwich)&#8221; as the Minimum SDK on the Target Android Devices screen. Uncheck all of the other checkboxes. Choose Next.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click Add No Activity on the Add an activity to Mobile screen.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Click Finish<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">At this point, Android Studio creates and open a project.\u00a0<\/span><\/p>\n<p><strong>Step4: Get the project ready<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">The list of the default project files that Android Studio has prepared is expandable in the Project sidebar. Open the build.gradle file that is linked to the &#8220;app&#8221; module (not the project) in that list by expanding the list of Gradle scripts. The <\/span><span style=\"font-weight: 400;\">first line should read\u00a0<\/span><b>apply plugin: &#8216;com.android.application&#8217;<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">In the toolbar, select\u00a0Tools &gt; Android &gt; Sync Project with Gradle Files. You will be able to use the libraries required for your project.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Find and open the default\u00a0src\/main\/AndroidManifest.xml\u00a0file. In the Project sidebar, this file is nested under\u00a0app\u00a0and then under\u00a0manifests. Replace the file&#8217;s contents with the following code:<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">&lt;manifest xmlns:android=&#8221;http:\/\/schemas.android.com\/apk\/res\/android&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 package=&#8221;com.example.quickstart&#8221;&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 &lt;uses-permission android:name=&#8221;android.permission.INTERNET&#8221; \/&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 &lt;uses-permission android:name=&#8221;android.permission.ACCESS_NETWORK_STATE&#8221; \/&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 &lt;uses-permission android:name=&#8221;android.permission.GET_ACCOUNTS&#8221; \/&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 &lt;application<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 android:allowBackup=&#8221;true&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 android:icon=&#8221;@mipmap\/ic_launcher&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 android:label=&#8221;YouTube Data API Android Quickstart&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 android:theme=&#8221;@style\/AppTheme&#8221; &gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 &lt;activity<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 android:name=&#8221;.MainActivity&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 android:label=&#8221;YouTube Data API Android Quickstart&#8221; &gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;intent-filter&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;action android:name=&#8221;android.intent.action.MAIN&#8221; \/&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;category android:name=&#8221;android.intent.category.LAUNCHER&#8221; \/&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;\/intent-filter&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 &lt;\/activity&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 &lt;\/application&gt;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">&lt;\/manifest&gt;<\/span><\/li>\n<\/ul>\n<p><strong>Step 5: setup sample<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Create a new Java class. Select the\u00a0java\u00a0folder in the Project sidebar. This folder appears in the group of\u00a0app\u00a0files. After clicking on the folder, you can select\u00a0<\/span><b>File<\/b><span style=\"font-weight: 400;\">\u00a0&gt;\u00a0<\/span><b>New<\/b><span style=\"font-weight: 400;\">\u00a0&gt;\u00a0<\/span><b>Java Class<\/b><span style=\"font-weight: 400;\">\u00a0from the menu bar, or you can right-click on the folder and select\u00a0<\/span><b>New<\/b><span style=\"font-weight: 400;\">\u00a0&gt;\u00a0<\/span><b>Java Class<\/b><span style=\"font-weight: 400;\">. If prompted to select a directory, choose\u00a0&#8230;\/app\/src\/main\/java.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Name the class &#8220;MainActivity&#8221; and click\u00a0<\/span><b>OK<\/b><span style=\"font-weight: 400;\">. Replace the contents of the new file with the following code.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">package com.example.quickstart;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import com.google.android.gms.common.ConnectionResult;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.android.gms.common.GoogleApiAvailability;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.extensions.android.http.AndroidHttp;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.googleapis.extensions.android.gms.auth.GooglePlayServicesAvailabilityIOException;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.http.HttpTransport;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.json.JsonFactory;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.json.jackson2.JacksonFactory;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.client.util.ExponentialBackOff;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.services.youtube.YouTubeScopes;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import com.google.api.services.youtube.model.*;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.Manifest;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.accounts.AccountManager;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.app.Activity;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.app.Dialog;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.app.ProgressDialog;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.content.Context;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.content.Intent;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.content.SharedPreferences;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.net.ConnectivityManager;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.net.NetworkInfo;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.os.AsyncTask;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.os.Bundle;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.support.annotation.NonNull;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.text.TextUtils;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.text.method.ScrollingMovementMethod;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.view.View;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.view.ViewGroup;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.widget.Button;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.widget.LinearLayout;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import android.widget.TextView;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import java.io.IOException;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import java.util.ArrayList;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import java.util.Arrays;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import java.util.List;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import pub.devrel.easypermissions.AfterPermissionGranted;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">import pub.devrel.easypermissions.EasyPermissions;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">public class MainActivity extends Activity<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 implements EasyPermissions.PermissionCallbacks {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 GoogleAccountCredential mCredential;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private TextView mOutputText;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private Button mCallApiButton;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 ProgressDialog mProgress;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 static final int REQUEST_ACCOUNT_PICKER = 1000;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 static final int REQUEST_AUTHORIZATION = 1001;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 static final int REQUEST_GOOGLE_PLAY_SERVICES = 1002;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 static final int REQUEST_PERMISSION_GET_ACCOUNTS = 1003;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private static final String BUTTON_TEXT = &#8220;Call YouTube Data API&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private static final String PREF_ACCOUNT_NAME = &#8220;accountName&#8221;;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private static final String[] SCOPES = { YouTubeScopes.YOUTUBE_READONLY };<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Create the main activity.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param savedInstanceState previously saved instance data.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 protected void onCreate(Bundle savedInstanceState) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 super.onCreate(savedInstanceState);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 LinearLayout activityLayout = new LinearLayout(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LinearLayout.LayoutParams.MATCH_PARENT,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LinearLayout.LayoutParams.MATCH_PARENT);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 activityLayout.setLayoutParams(lp);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 activityLayout.setOrientation(LinearLayout.VERTICAL);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 activityLayout.setPadding(16, 16, 16, 16);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 ViewGroup.LayoutParams tlp = new ViewGroup.LayoutParams(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ViewGroup.LayoutParams.WRAP_CONTENT,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ViewGroup.LayoutParams.WRAP_CONTENT);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mCallApiButton = new Button(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mCallApiButton.setText(BUTTON_TEXT);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mCallApiButton.setOnClickListener(new View.OnClickListener() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 public void onClick(View v) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mCallApiButton.setEnabled(false);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getResultsFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mCallApiButton.setEnabled(true);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 });<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 activityLayout.addView(mCallApiButton);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText = new TextView(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setLayoutParams(tlp);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setPadding(16, 16, 16, 16);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setVerticalScrollBarEnabled(true);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setMovementMethod(new ScrollingMovementMethod());<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;Click the \\'&#8221; + BUTTON_TEXT +&#8221;\\&#8217; button to test the API.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 activityLayout.addView(mOutputText);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mProgress = new ProgressDialog(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mProgress.setMessage(&#8220;Calling YouTube Data API &#8230;&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 setContentView(activityLayout);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ Initialize credentials and service object.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 mCredential = GoogleAccountCredential.usingOAuth2(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getApplicationContext(), Arrays.asList(SCOPES))<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .setBackOff(new ExponentialBackOff());<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Attempt to call the API, after verifying that all the preconditions are<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* satisfied. The preconditions are: Google Play Services installed, an<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* account was selected and the device currently has online access. If any<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* of the preconditions are not satisfied, the app will prompt the user as<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* appropriate.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private void getResultsFromApi() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 if (! isGooglePlayServicesAvailable()) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 acquireGooglePlayServices();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 } else if (mCredential.getSelectedAccountName() == null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chooseAccount();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 } else if (! isDeviceOnline()) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;No network connection available.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 new MakeRequestTask(mCredential).execute();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Attempts to set the account used with the API credentials. If an account<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* name was previously saved it will use that one; otherwise an account<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* picker dialog will be shown to the user. Note that the setting the<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* account to use with the credentials object requires the app to have the<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* GET_ACCOUNTS permission, which is requested here if it is not already<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* present. The AfterPermissionGranted annotation indicates that this<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* function will be rerun automatically whenever the GET_ACCOUNTS permission<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* is granted.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @AfterPermissionGranted(REQUEST_PERMISSION_GET_ACCOUNTS)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private void chooseAccount() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 if (EasyPermissions.hasPermissions(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 this, Manifest.permission.GET_ACCOUNTS)) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String accountName = getPreferences(Context.MODE_PRIVATE)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .getString(PREF_ACCOUNT_NAME, null);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (accountName != null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mCredential.setSelectedAccountName(accountName);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getResultsFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Start a dialog from which the user can choose an account<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 startActivityForResult(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mCredential.newChooseAccountIntent(),<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 REQUEST_ACCOUNT_PICKER);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Request the GET_ACCOUNTS permission via a user dialog<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 EasyPermissions.requestPermissions(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 this,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;This app needs to access your Google account (via Contacts).&#8221;,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 REQUEST_PERMISSION_GET_ACCOUNTS,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Manifest.permission.GET_ACCOUNTS);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Called when an activity launched here (specifically, AccountPicker<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* and authorization) exits, giving you the requestCode you started it with,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* the resultCode it returned, and any additional data from it.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param requestCode code indicating which activity result is incoming.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param resultCode code indicating the result of the incoming<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* \u00a0 \u00a0 activity result.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param data Intent (containing result data) returned by incoming<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* \u00a0 \u00a0 activity result.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 protected void onActivityResult(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 int requestCode, int resultCode, Intent data) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 super.onActivityResult(requestCode, resultCode, data);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 switch(requestCode) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 case REQUEST_GOOGLE_PLAY_SERVICES:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (resultCode != RESULT_OK) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;This app requires Google Play Services. Please install &#8221; +<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;Google Play Services on your device and relaunch this app.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getResultsFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 break;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 case REQUEST_ACCOUNT_PICKER:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (resultCode == RESULT_OK &amp;&amp; data != null &amp;&amp;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 data.getExtras() != null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 String accountName =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (accountName != null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 SharedPreferences settings =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getPreferences(Context.MODE_PRIVATE);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 SharedPreferences.Editor editor = settings.edit();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 editor.putString(PREF_ACCOUNT_NAME, accountName);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 editor.apply();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mCredential.setSelectedAccountName(accountName);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getResultsFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 break;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 case REQUEST_AUTHORIZATION:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (resultCode == RESULT_OK) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 getResultsFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 break;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Respond to requests for permissions at runtime for API 23 and above.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param requestCode The request code passed in<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* requestPermissions(android.app.Activity, String, int, String[])<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param permissions The requested permissions. Never null.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param grantResults The grant results for the corresponding permissions<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* which is either PERMISSION_GRANTED or PERMISSION_DENIED. Never null.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 public void onRequestPermissionsResult(int requestCode,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@NonNull String[] permissions,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0@NonNull int[] grantResults) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 super.onRequestPermissionsResult(requestCode, permissions, grantResults);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 EasyPermissions.onRequestPermissionsResult(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 requestCode, permissions, grantResults, this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Callback for when a permission is granted using the EasyPermissions<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* library.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param requestCode The request code associated with the requested<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\u00a0 \u00a0 \u00a0 \u00a0 \u00a0permission<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param list The requested permission list. Never null.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 public void onPermissionsGranted(int requestCode, List&lt;String&gt; list) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ Do nothing.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Callback for when a permission is denied using the EasyPermissions<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* library.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param requestCode The request code associated with the requested<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* \u00a0 \u00a0 \u00a0 \u00a0 permission<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param list The requested permission list. Never null.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 public void onPermissionsDenied(int requestCode, List&lt;String&gt; list) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ Do nothing.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Checks whether the device currently has a network connection.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @return true if the device has a network connection, false otherwise.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private boolean isDeviceOnline() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 ConnectivityManager connMgr =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 return (networkInfo != null &amp;&amp; networkInfo.isConnected());<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Check that Google Play services APK is installed and up to date.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @return true if Google Play Services is available and up to<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* \u00a0 \u00a0 date on this device; false otherwise.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private boolean isGooglePlayServicesAvailable() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 GoogleApiAvailability apiAvailability =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 GoogleApiAvailability.getInstance();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 final int connectionStatusCode =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 apiAvailability.isGooglePlayServicesAvailable(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 return connectionStatusCode == ConnectionResult.SUCCESS;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Attempt to resolve a missing, out-of-date, invalid or disabled Google<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Play Services installation via a user dialog, if possible.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private void acquireGooglePlayServices() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 GoogleApiAvailability apiAvailability =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 GoogleApiAvailability.getInstance();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 final int connectionStatusCode =<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 apiAvailability.isGooglePlayServicesAvailable(this);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 if (apiAvailability.isUserResolvableError(connectionStatusCode)) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Display an error dialog showing that Google Play Services is missing<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* or out of date.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* @param connectionStatusCode code describing the presence (or lack of)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* \u00a0 \u00a0 Google Play Services on this device.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 void showGooglePlayServicesAvailabilityErrorDialog(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 final int connectionStatusCode) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 Dialog dialog = apiAvailability.getErrorDialog(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 MainActivity.this,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 connectionStatusCode,<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 REQUEST_GOOGLE_PLAY_SERVICES);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 dialog.show();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* An asynchronous task that handles the YouTube Data API call.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0* Placing the API calls in their own task ensures the UI stays responsive.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 private class MakeRequestTask extends AsyncTask&lt;Void, Void, List&lt;String&gt;&gt; {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 private com.google.api.services.youtube.YouTube mService = null;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 private Exception mLastError = null;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 MakeRequestTask(GoogleAccountCredential credential) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 HttpTransport transport = AndroidHttp.newCompatibleTransport();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mService = new com.google.api.services.youtube.YouTube.Builder(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 transport, jsonFactory, credential)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .setApplicationName(&#8220;YouTube Data API Android Quickstart&#8221;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .build();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* Background task to call YouTube Data API.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* @param params no parameters needed for this task.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 protected List&lt;String&gt; doInBackground(Void&#8230; params) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 try {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return getDataFromApi();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } catch (Exception e) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mLastError = e;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 cancel(true);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return null;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/**<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* Fetch information about the &#8220;GoogleDevelopers&#8221; YouTube channel.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* @return List of Strings containing information about the channel.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* @throws IOException<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0*\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 private List&lt;String&gt; getDataFromApi() throws IOException {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Get a list of up to 10 files.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 List&lt;String&gt; channelInfo = new ArrayList&lt;String&gt;();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ChannelListResponse result = mService.channels().list(&#8220;snippet,contentDetails,statistics&#8221;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.setForUsername(&#8220;GoogleDevelopers&#8221;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0.execute();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 List&lt;Channel&gt; channels = result.getItems();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (channels != null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Channel channel = channels.get(0);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 channelInfo.add(&#8220;This channel&#8217;s ID is &#8221; + channel.getId() + &#8220;. &#8221; +<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;Its title is &#8216;&#8221; + channel.getSnippet().getTitle() + &#8220;, &#8221; +<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &#8220;and it has &#8221; + channel.getStatistics().getViewCount() + &#8221; views.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return channelInfo;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 protected void onPreExecute() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mProgress.show();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 protected void onPostExecute(List&lt;String&gt; output) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mProgress.hide();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (output == null || output.size() == 0) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;No results returned.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 output.add(0, &#8220;Data retrieved using the YouTube Data API:&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(TextUtils.join(&#8220;\\n&#8221;, output));<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 @Override<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 protected void onCancelled() {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mProgress.hide();<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (mLastError != null) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (mLastError instanceof GooglePlayServicesAvailabilityIOException) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 showGooglePlayServicesAvailabilityErrorDialog(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ((GooglePlayServicesAvailabilityIOException) mLastError)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .getConnectionStatusCode());<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else if (mLastError instanceof UserRecoverableAuthIOException) {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 startActivityForResult(<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ((UserRecoverableAuthIOException) mLastError).getIntent(),<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 MainActivity.REQUEST_AUTHORIZATION);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;The following error occurred:\\n&#8221;<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 + mLastError.getMessage());<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 } else {<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 mOutputText.setText(&#8220;Request cancelled.&#8221;);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><strong>Step6: Run the App<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">To test the app, click the Run and Run App from the menu.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You will need to choose\u00a0 the connected device (recommended) or an emulator. If you use an emulator, make sure it is set up to use one of the system images for the Google APIs. The quickstart generates a dialogue from which you may install Google Play services if you try to run it on a device that doesn&#8217;t already have them set up.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If you are using an emulator allow it to fully start up and establish its network.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You might need to unlock the emulator&#8217;s screen if you&#8217;re starting it for the first time. However, the quickstart app ought to launch automatically.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The software asks you to provide an account information when you launch it for the first time. To select an account to connect to, complete the sign-in process.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">The application asks you to authorize access when you choose an account. Click OK to confirm.<\/span><\/li>\n<\/ul>\n<p style=\"text-align: center;\"><strong>Also read:\u00a0<a href=\"https:\/\/unremot.com\/blog\/tool-integration-for-business-workflow\/\">Tool integration: Why is it important for your business workflow between departments?<\/a><\/strong><\/p>\n<h2><b>YouTube API pricing<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The YouTube Data API is free API and Google does not charge you for accessing the YouTube API. YouTube API has restricted number of usages or number of requests your application can make to an API over a period of time (quota). The default cap for any Google Cloud project is 10,000 units each day. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">This is usually sufficient for most API users. If you would like to request additional quota your project will be audited to ensure it complies with YouTube API terms of service. You can view <\/span><a href=\"https:\/\/developers.google.com\/youtube\/v3\/determine_quota_cost\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Quota Calculator<\/span><\/a><span style=\"font-weight: 400;\"> to calculate the cost for calling different API methods.\u00a0<\/span><\/p>\n<h2><b>What is YouTube music API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Ytmusicapi is a Python 3 library that sends requests to the YouTube music API. You can find Ytmusicapi in GitHub. The API allows for the following features \u2013\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Browsing<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Explore music<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Library management<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Playlist\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Uploads<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">What is YouTube search API?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">YouTube search API endpoint allows you to scrape the result from YouTube search engine via the SerpAPIService. Common parameters used \u2013<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">search_query &#8211; <\/span><span style=\"font-weight: 400;\">Parameter defines the search query. You can use anything that you would use in a regular YouTube search.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Localization \u2013 Paraamter defines the language and region of the search results. You can specify geographical and linguistic specific results.\u00a0<\/span><\/li>\n<\/ul>\n<h2><b>What is YouTube analytics API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You can use YouTube analytics API to create unique reports. Both channels and content owners can access reports via the API. There are two types of report fields: dimensions and metrics.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Dimensions are conventional criteria used to aggregate data, like the user\u2019s country or the date of the action.\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Each data row in the report has a different set of dimensional values. YouTube calculates the values of the report based on the dimensions selected you select.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Metrics are specific measurements of user behavior, ad effectiveness, or projected revenue. Metrics tracking user activity include things like rating and view counts. The analytics API offers filtering and sorting therefore the caller application is not required to have native support for those features.<\/span> <span style=\"font-weight: 400;\">The API also enables you to access data for groups created by YouTube Analytics, which can contain up to 500 videos, playlists, channels, or other assets.<\/span><\/li>\n<\/ul>\n<h2><b>What is YouTube shorts API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">YouTube Shorts are short videos that anyone can make using their mobile phones. Developers can use YouTube Shorts API to incorporate Shorts functionality into their products or services. It enables programmers to make tools that let users interact with Shorts material, upload and share videos, and access licensed music and sound effects. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Along with data to assist developers monitor performance and user engagement, the API offers capabilities for controlling Shorts content.<\/span><\/p>\n<h2><b>What is YouTube player API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Coders can use the\u00a0 YouTube player API to embed a YouTube Player on your website and control it with JavaScript. You can queue videos for playback, start, pause, or stop them, change the player volume, or get details about the video that is now playing using the JavaScript functions of the API. Additionally, you can include event listeners, which will run in reaction to certain player events like a player status change.<\/span><\/p>\n<p style=\"text-align: center;\"><strong>Also read: <\/strong><a href=\"https:\/\/hbr.org\/2021\/04\/apis-arent-just-for-tech-companies\" target=\"_blank\" rel=\"noopener\">APIs Aren&#8217;t Just for Tech Companies<\/a><\/p>\n<h2><b>What is YouTube ads API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">YouTube advertising are a popular medium of communication, and you pay only when people watch your ads. The YouTube ads API is a programming int<\/span><span style=\"font-weight: 400;\">erface for Google Ads is the Google Ads API. Developers can use it to communicate directly with the Google Ad platform, improving the effectiveness of handling extensive or intricate YouTube Ad campaigns. Some use scenarios are-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Automated account management<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Custom reporting<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ad management based on inventory<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Manage Smart Bidding strategies<\/span><\/li>\n<\/ul>\n<h2><b>What is YouTube reporting API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">YouTube <a href=\"https:\/\/developers.google.com\/youtube\/reporting\/v1\/reports\" target=\"_blank\" rel=\"noopener\">Reporting API<\/a> and YouTube Analytical Data lets you get YouTube Analytics data to automate challenging reporting tasks, create custom dashboards, and much more. You can use the Reporting API to support applications and collect and store bulk reports and provide tools for data mining, filtering, and sorting.\u00a0 The <a href=\"https:\/\/developers.google.com\/youtube\/analytics\" target=\"_blank\" rel=\"noopener\">Analytics API<\/a> allows for focused immediate queries that produce a personalized response to user input.<\/span><\/p>\n<h2><b>What is YouTube feed API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The YouTube Feed API is a subset of the <a href=\"https:\/\/developers.google.com\/youtube\/v3\" target=\"_blank\" rel=\"noopener\">YouTube Data API<\/a> that enables developers to get and display specified subsets of YouTube video material, such as user-uploaded videos, the most recent uploads to a channel, or the most well-liked videos in a given area or category. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">By integrating this API into their own applications and services, developers may utilize it to build unique video feeds that let consumers browse and watch YouTube content without ever leaving their platform.<\/span><\/p>\n<h2><b>What is YouTube livestream API?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You may create, update, and administer live events on YouTube using the YouTube Live Streaming API. The API allows you to schedule broadcasts and link them to video streams, which serve as the broadcast&#8217;s real content.<\/span> <span style=\"font-weight: 400;\">Actually, parts of the YouTube Data API and YouTube Content ID API make up the Live Streaming API. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Users of YouTube can manage their accounts using the Data API, and they can engage with YouTube&#8217;s rights management system using the YouTube Content ID API. But only live events are created and managed using the resources that make up the Live Streaming API.<\/span><\/p>\n<h2><b>How to Hire YouTube API developers?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Before you hire YouTube API developers you need to create a project outline and define the roles of the project manager. You can post your requirements or relevant job boards like <a href=\"https:\/\/beta.unremot.com\/category\/youtube-api\">Unremot<\/a>, Upwork, and LinkedIn. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Remember to add requirements such as skills required, experiences, project time frame, and budget. <\/span><span style=\"font-weight: 400;\">After shortlisting candidates, you can conduct interviews to assess candidates and carry out reference checks. Once you have found your candidate make an offer that details the scope of their work and compensation.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let us understand how to use YouTube API &#8211; A Step-By-Step guide to Integrate YouTube API and full documentation list. Overview of YouTube API The YouTube API is an application program interface that enables you to curate a playlist, and embedded videos, and provides other YouTube features on your website. Thanks to the API organizations [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":5188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[76],"tags":[],"class_list":{"0":"post-5162","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-technology","8":"entry"},"_links":{"self":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/comments?post=5162"}],"version-history":[{"count":32,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5162\/revisions"}],"predecessor-version":[{"id":5206,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/posts\/5162\/revisions\/5206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media\/5188"}],"wp:attachment":[{"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/media?parent=5162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/categories?post=5162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unremot.com\/blog\/wp-json\/wp\/v2\/tags?post=5162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}