Friday , August 18 2017 12:34 PM
Home / Tutorials / PHP / Server-side YouTube V3 OAuth API (CakePHP)

Server-side YouTube V3 OAuth API (CakePHP)

To make this work, you’ll need to create a dummy web application that can capture the refresh token generated when you authorize your am using this as a cakePHP component.

Creating your project

  1. You’ll need to head over to and create a new project.
  2. Then go and enable the YouTube Data API – (Your Project > APIS & AUTH > APIs)
  3. We’ll now need to create some credentials. Go to Your Project > APIS & AUTH > Credentials
  4. Click “Create new Client ID” and then under “Application Type” select “Web Application”.
  5. You’ll then need to enter your JavaScript origin and authorised redirect URI. I just set this to localhost, but you can set it to where ever you want.
  6. We’ve now created our client ID, we just need to fill in the Consent Screen. We can do this by navigating to Your Project > APIS & AUTH > Consent Screen. Once you’re on this page, ensure you fill out all the required fields (Email Address and Product Name).
  7. Cool, we’ve created our project.

Getting your refresh token

I used the following PHP script as my dummy application to generate the OAuth token. This script utilises Google APIs Client Library for PHP.  You’ll need to download and install it using Composer because google strictly need Composer.

Saving your credentials

Now that you’ve received your refresh tokens create a text file called “token.txt” with the following information you’ve just received, it should look something similar to the format below:

Creating the upload script

The script below is a very basic implementation. It requires the following file structure (app/Vendor):

  • Google/
  • auth.php (for genenrate refresh token above script)
  • token.txt (the file we created in the previous section) give 777 permission ($sudo chmod 777 token.txt)
Hopefully that’s enough to get your started, if you have any questions feel free to ask 🙂

Check Also

Don’t Fall For This Dangerously Convincing Ongoing Phishing Attack

Security researchers have discovered a new phishing campaign targeting Gmail users, which is so convincing …

Powered by