2 – Setting up your Google Account and API Console

This is article 2 of the YouTube API With PHP series.

 GOOGLE ACCOUNT

Before you can actually start using the YouTube API, you have to register for a Google account. Chances are you already have a google account in the form of a Gmail id. If you use Gmail, then your email id is your Google Account. If you have a YouTube account, that is also your Google Account.

Google Accounts is the single membership control center for all of Google’s services and products. So one google login works for all of them. To manage your Google account, go to http://accounts.google.com.

Here is a screenshot of how it looks:

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Your Google account is important because it will be used to access the Google API Console, from where you can enable and activate the YouTube API. The YouTube API is not usable without an API key and that API key is only available if you have a registered Google account.

 

GOOGLE API CONSOLE

We will now obtain an API Key for use within your code.

1.Go to https://console.developers.google.com/ This is how it looks for me. You might not have the dropdown of applications at the top left corner as I have. Click on the dropdown and click on + icon which shows in the popup as shown in the screenshot below:

2

 

 

 

 

 

 

 

 

 

 

 

 

 

3

 

 

 

 

 

 

 

 

 

 

 

 

 

2.Fill in a project name of your choice and click Submit.

4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.Now in the Dashboard page, click on the Enable API button at the top.

5

 

 

 

 

 

 

 

 

 

 

 

 

 

4.This will take you to the Library page which lists all the available Google API services. Locate the APIs for YouTube .

6

 

 

 

 

 

 

 

 

 

 

 

 

 

5.Click on YouTube Data API. This will bring up the screen below.  Click the Enable button at the top.

7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.This brings you back to the Dashboard page with traffic statistics data.

8

 

 

 

 

 

 

 

 

 

 

 

 

 

7.Click on the Create Credentials button. This brings the screen below. Choose API Key in the dropdown.

9

 

 

 

 

 

 

 

 

 

 

 

 

 

8.Click Close after that. Do not worry about the Restrict Key option for now. We will come to that later.

10

 

 

 

 

 

 

 

 

 

 

 

 

 

9.This will bring you back to the Dashboard page. Take note of the API key as you will need to use it in your code.

11

 

 

 

 

 

 

 

 

 

 

 

 

 

10.Go back to the dashboard page and again click on Enable API button. Select YouTube Analytics API . Enable it as in the previous steps. Do NOT do the Create Credentials steps . Repeat the same process for YouTube Reporting API. Your dashboard should now look like this:

12

 

 

 

 

 

 

 

 

 

 

 

 

 

 

11.Now we will setup OAuth credentials for our web application. Go to the Credentials page , click on Create Credentials button and select OAuth Client id from the dropdown.

13

 

 

 

 

 

 

 

 

 

 

 

 

 

12.On the next page click on the Configure Consent screen button.

14

 

 

 

 

 

 

 

 

 

 

 

 

 

13.Enter a Product name and click on Save

15

 

 

 

 

 

 

 

 

 

 

 

 

 

14.Now in the Create Client Id page, choose Web Application as the Application type and click Create

16

 

 

 

 

 

 

 

 

 

 

 

 

 

15.This will generate the Client ID and the Client secret which your code will use when accessing user-authenticated data.

17

 

 

 

 

 

 

 

 

 

 

 

 

 

16.Your Credentials page should look something like this:

18

 

 

 

 

 

 

 

 

 

 

 

 

 

17.One last step remaining is setting the OAuth Redirect URL. This will be explained later in the relevant section, but for now we will just add it in the API Console. Click on the Edit icon next to the OAuth 2.0 client ID item. This will take you to the edit page where you will  fill in the value for Authorized Redirect URLs. Most likely you are running your code in a localhost so you can put the url as http://localhost/YouTubeapi/oauthreponse.php and click on Save.

This value is what works when running the sample code in this book. But once you are clear on what it actually does, you can change it to whatever url you want. You can enter multiple URLs if required. The explanation for redirect url is in the Coding Patterns section.

19

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This concludes the activation of the YouTube APIs for your Google account.

Be the first to comment

Leave a Reply

Your email address will not be published.


*