> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safesquid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# YouTube API Integration

> Integrate YouTube API with SafeSquid to allow or block YouTube videos by category for productivity and bandwidth control.

## Problem

Security teams need predictable control over app and web usage to reduce policy bypass and data-risk exposure.

## Benefits

You can enforce policy decisions consistently with SafeSquid while preserving legitimate business workflows.

## Advantages

You keep actionable policy control close to operations, with verifiable outcomes in logs and policy behavior.

## Call to action

Use the steps in this guide to implement the control, then validate behavior with a real user-flow test.

# Allow or block YouTube by category via YouTube API

YouTube offers entertainment and educational content; unrestricted viewing can reduce productivity and bandwidth. SafeSquid integrates with the YouTube API to identify video categories. Policies can allow or block specific categories so organizations permit learning and marketing content while blocking unrelated videos.

## Client scenario (case study)

Ganpat University provides graduate programs to various colleges. All the staff's PC/Laptop traffic is going via SafeSquid SWG.

Ganpat University wants to block entire youtube.com for faculty and students, but wants some of the YouTube channels allowed which are helpful for faculty/students.

Ganpat University challenges are:

All staff/Students should not be allowed to access [www.youtube.com](http://www.youtube.com). If any faculty/student try to access YouTube then he/she should get blocked template.

Only few of the specified YouTube channel and its playlist should be allowed. These YouTube channel contains educational and knowledge sharing videos.

SafeSquid SWG give them solution for the above requirement.

You can achieve this by creating policy in Request Profiles Section and bind it with policies in Access Profiles Section.

You need YouTube Channel-ID and List-ID of playlist, you want to allow.

You have to extract Channel-ID and List-ID of the playlist from YouTube URL before creating policies in SafeSquid.All the

Mr. Haresh is the system administrator of Ganpat University. From last few months he received the request from faculty for allowing many other videos/Playlist/channels etc.

Of course, all the videos/Playlist/channel etc. are educational and knowledge sharing.

But he faces some difficulty for extracting Channel-ID and List-ID of the requested playlist/channel regularly.

SafeSquid SWG has given them the fantastic solution for Mr. Haresh difficulty.

The latest Version of SafeSquid (Versions August onward) includes **YouTube API Integration with SafeSquid-SWG**. That means you can now create Policies on the basis of YouTube Categories.

You can now allow/block specific category of videos on YouTube.

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/cI-kUTNiWWPhOtFM/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image1.webp?fit=max&auto=format&n=cI-kUTNiWWPhOtFM&q=85&s=9913084a9528ffda5e5b475c026f5d54" alt="Find category to allow or block Youtube video" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image1.webp" />

## Prerequisites

HTTPS Inspection should be enabled in SafeSquid. If not enabled, you can check our document - How to enable HTTPS Inspection

## Create a YouTube V3 API using your Google Account.

To Request the Category of Specific Video

To extract Video Category from Video ID

Go To [https://console.developers.google.com/apis/library](https://console.developers.google.com/apis/library) [Link](https://console.cloud.google.com/apis/library)

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image2.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=5adfab1d9f7405fd023144e76d960671" alt="Create a Youtube V3 API using google account for Youtube API integration with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image2.webp" />

:::note
What happens over here is If you don't Create a Project over here, Google will Automatically Create a new Project for you Named as "My First Project" when you ENABLE the YouTube Data API v3.
:::

People doing it for the first time and have requirement to use YouTube Data API v3 to integrate it with SafeSquid-SWG.

I recommend creating a New Project with a Proper name so that you can later identify it.

Since they have specified Per Day Quota i.e. No of Request to find Information about a Particular video and its details.

Make sure that this Google Account is not using YouTube API for any other purposes as this will reduce the No of Request

## CREATE A NEW PROJECT

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image3.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=e5f60c172a886256afa629439067a620" alt="Click on select a project to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image3.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image4.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=b92a10962c563bc378d90b02b3797bfd" alt="Click on project to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image4.webp" />

### Name as: YouTubeAPI-For-SafeSquid

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image5.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=78efe025bc4f1bfb6ca90042fa2e5481" alt="Name and create a project to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image5.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image6.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=4b4ab3ef95f656c0d13bf4a39629305d" alt="Redirect to API Library in API & Services section" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image6.webp" />

### Select a project

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image7.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=4ac97f8f2bec0af231de3900b31f91f4" alt="Select a project to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image7.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image8.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=e5bd2d0d23afd63e23d3259370e54c0a" alt="Get a access of API Library" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image8.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image9.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=ffcb61099153bace2f9b1bd3e936af1e" alt="Select YOUTUBE DATA API V3 to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image9.webp" />

### Enable YouTube Data API V3

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/cI-kUTNiWWPhOtFM/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image10.webp?fit=max&auto=format&n=cI-kUTNiWWPhOtFM&q=85&s=1f273dac8e51d00e2cc0fe3e3bbc9e21" alt="ENABLE YOUTUBE DATA API V3 to" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image10.webp" />

### Create credentials

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/cI-kUTNiWWPhOtFM/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image11.webp?fit=max&auto=format&n=cI-kUTNiWWPhOtFM&q=85&s=580a6f7d2d151640f324234b2065f8a8" alt="Select a Create credentials to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image11.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image12.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=a9d154912d170b6ddfc4949d2458c287" alt="Click on Create credentials to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image12.webp" />

### Select API key

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image13.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=627899396e0e993c1f2288433d45d75f" alt="select API key to create API keys " width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image13.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image14.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=f23bf49bfc1529a472583ffa2c504861" alt="Google generate Youtube API keys" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image14.webp" />

## Integrate the YouTube API Key in SafeSquid.

**To identify the category of the YouTube video**

Now we are going to Integrating this Key in SafeSquid-SWG.

To do that, Go to SafeSquid console.

Go to the path using below command:

```bash theme={null}
cd /var/lib/safesquid/
```

Create the directory using below command:

```bash theme={null}
mkdir youtube
```

Give the permission using below command:

chmod 774 youtube

chown ssquid:root youtube

root\@safesquid-swg:/var/lib/safesquid# ll

total 56

drwxrwxr-- 12 ssquid root 4096 Aug 29 15:35 ./

drwxr-xr-x 48 root root 4096 Jul 4 19:06 ../

drwxrwxr-- 3 ssquid root 4096 Jan 21 2019 application\_signatures/

drwxrwxr-- 2 ssquid root 4096 Sep 5 14:03 category/

drwxrwxr-- 3 ssquid root 4096 Apr 2 18:44 content\_signatures/

drwxrwxr-- 2 ssquid root 4096 Jan 21 2019 imgfilter/

drwxrwxr-- 3 ssquid root 12288 Sep 5 13:47 sqscan/

drwxrwxr-- 3 ssquid root 4096 May 30 14:17 sscore/

drwxrwxr-- 4 ssquid root 4096 Sep 5 14:03 sscore2/

drwxrwxr-- 2 ssquid root 4096 Jun 13 19:12 ssqore/

drwxrwxr-- 4 ssquid root 4096 Sep 5 14:03 svscan/

drwxrwxr-- 2 ssquid root 4096 Aug 23 14:53 youtube/

Go to youtube directory using command:

root\@safesquid-swg:/var/lib/safesquid#cd youtube

Copy YouTube API Key using WinSCP or any other tool at given path **/var/lib/safesquid/youtube/**

root\@safesquid-swg:/var/lib/safesquid/youtube# ll

total 16

drwxrwxr-- 2 ssquid root 4096 Aug 23 14:53 ./

drwxrwxr-- 12 ssquid root 4096 Aug 29 15:35 ../

-rw-rw-r-- 1 ssquid root 40 Jul 3 14:11 keys

-rw-rw-r-- 1 ssquid root 947 Jul 3 14:12 legends

After adding key, the file will look like this

root\@safesquid-swg:cat /var/lib/safesquid/youtube/keys

AIz\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*o

After adding the API key, **restart the SafeSquid service** from the SafeSquid Interface or via command line:

```bash theme={null}
/etc/init.d/safesquid restart
```

:::note
Please Restart SafeSquid Twice in order to Integrate YouTube API properly.
:::

You have successfully integrated YouTube API with SafeSquid-SWG.

Now, Go ahead with Policy creation on the basis of YouTube Categories.

To do so, I will help you out in creating a simple Policy which will only allow Specific YouTube Category VIA SafeSquid all other YouTube Videos will be blocked.

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image15.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=8b76d52e2477aa9f0d6b7eac336c8039" alt="Click on configure to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image15.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image16.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=fb343da49f26faa847a36fc62f97f0c1" alt="Policy to integrate Youtube API with safesquid" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image16.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image17.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=6ae5bcb98b1d8591bdfb7be8fd4416cd" alt="Youtube Video policy to allow specific video" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image17.webp" />

<img src="https://mintcdn.com/safe-squid-labs-12a0916f/2cNDqI_cln6wbLTp/images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image18.webp?fit=max&auto=format&n=2cNDqI_cln6wbLTp&q=85&s=18b24281243617bfb694d497b7435713" alt="Youtube Video policy to allow specific video" width="1280" height="720" data-path="images/How_To/YouTube_API_Integration_With_SafeSquid_To_Allow_Specific_YouTube_Videos/image18.webp" />


## Related topics

- [Block Specific YouTube Channel](/use_cases/access_restriction/block_specific_youtube_channel.md)
- [Allow Specific YouTube Channel and its Playlist](/use_cases/access_restriction/allow_specific_youtube_channel_and_its_playlist.md)
- [Content rewrite](/admin_guide/filtering_and_privacy/content_modifier.md)
- [Header Filter Configuration and Reference](/use_cases/header_rewrite/header_filter_configuration.md)
- [SSL Certification Errors](/troubleshooting/ssl_inspection_issues.md)
