# Import YouTube Videos

1. [Add An Importer](#frontend-dashboard-screen)
2. [Authenticate with Google OAuth](#google-oauth) (New - Since 4.0)
3. [Assign Capabilities](#assign-capabilities)
4. [Create A YouTube API Key](#manual-import) (**deprecated**)
5. [Manual Import](https://phpface.ticksy.com/article/19794/#manual-import)
6. [Auto Import Using Hosting Cronjob](#hosting-cronjob) (**deprecated**)
7. [Auto Import Using WP Control Plugin](#wp-control) (**deprecated**)
8. [Filter Post Arguments](#filter-post-arguments)

***

#### Frontend Dashboard Screen

{% hint style="success" %}
Since version 4.0, the YouTube Importer UI can be managed directly from the frontend dashboard, just like in the backend. See "**Backend Screen - Add An Importer**" below for further instructions on how to add importers.
{% endhint %}

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FHoWLcXq5zNgaOIy5wfz5%2F7927690333.png?alt=media&#x26;token=ea911213-49b0-44c6-890a-f992ebce7462" alt=""><figcaption></figcaption></figure>

{% embed url="<https://www.youtube.com/watch?v=OpaJ13YHJCY>" %}
Create Google OAuth Project
{% endembed %}

{% hint style="info" %}
Your app may need to be verified. Follow the Manage OAuth App Branding guide for further instructions <https://support.google.com/cloud/answer/15549049?sjid=17774368760552836686-NC>
{% endhint %}

***

The YouTube Importer screen is displayed for administrators by default. To grant access to regular members, follow these steps:

1. Navigate to your Frontend **Dashboard > Settings > Capabilities**.
2. Select "Post Type: YouTube Importer".
3. Choose a specific user role to grant permissions to, or select "**All**" to apply changes to all roles.
4. Check the necessary capability checkboxes.

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2F238D60wcTi1kI9SylCAW%2F5505844889.png?alt=media&#x26;token=c914230b-9263-483f-8491-09fc9a041a99" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
For more information about Content Capablities, please refer to [content-capabilities](https://phpface.gitbook.io/streamtube/content-capabilities "mention")
{% endhint %}

{% hint style="danger" %}
Avoid granting "**edit\_others\_yt\_importers**" and "**delete\_others\_yt\_importers**" capabilities, as these are intended for moderators such as administrators and editors only.
{% endhint %}

***

#### Backend Screen - Add An Importer <a href="#add-importer" id="add-importer"></a>

***

Navigate to **Videos > YouTube Importers > Add New**

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2F8U6eAMh4x4pg5RjFofAC%2F6146724388.png?alt=media&#x26;token=3d3391a1-a6f6-4abc-ab54-75d846d968b9" alt=""><figcaption></figcaption></figure>

1. **Add Title**: Enter a custom title for the importer, for example: My Music
2. **Enable**: Enable the importer in case of running automatically via hosting Cron Job
3. **Youtube API Key** : Enter your own **Youtube API key**
4. **Search**: Specifies the query term to search for. Your request can also use the Boolean NOT (-) and OR (|) operators to exclude videos or to find videos that are associated with one of several search terms. For example, to search for videos matching either "**boating**" or "**sailing**", set the search field value to **boating|sailing**. Similarly, to search for videos matching either "**boating**" or "**sailing**" but not "**fishing**", set the search field value to **boating|sailing -fishing**.
5. **Channel/Playlist ID**: The field value indicates that the API response should only contain resources created by the channel.
6. **Max Results** Specifies the maximum number of items that should be returned in the result set. Acceptable values are 0 to 50
7. **Event Type**: Restricts a search to broadcast events
8. **Video Type**: Restrict a search to a particular type of videos
9. **Safe Search**: Indicates whether the search results should include restricted content as well as standard content.
10. **Video Definition**: Restrict a search to only include either high definition (HD) or standard definition (SD) videos. HD videos are available for playback in at least 720p, though higher resolutions, like 1080p, might also be available
11. **Video Dimension**: Restrict a search to only retrieve 2D or 3D videos
12. **Video Duration**: Filters video search results based on their duration
13. **Video License**: Filters search results to only include videos with a particular license. YouTube lets video uploaders choose to attach either the Creative Commons license or the standard YouTube license to each of their videos.
14. **Published After**: Indicates that the API response should only contain resources created at or after the specified time
15. **Published Before**: Indicates that the API response should only contain resources created before or at the specified time
16. **Region Code**: Instructs the API to return search results for videos that can be viewed in the specified country
17. **Relevance Language**: Instructs the API to return search results that are most relevant to the specified language
18. **Video Categories**: Choose the video categories the videos will be imported to
19. **Video Tags**: Choose the video tags the videos will be imported to
20. **Import Tags**: Imports video keywords

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FZ82Jmu3TwfLJ5hily1zS%2F6145260171.png?alt=media&#x26;token=b0f1cf4b-374d-4bee-bcd4-d139746314c1" alt=""><figcaption></figcaption></figure>

You can add many importers as you wish

***

#### Authenticate with Google OAuth <a href="#google-oauth" id="google-oauth"></a>

{% hint style="success" %}
Since version 4.0, there is no need to manually create an API key, as the theme now supports authentication using Google OAuth. This ensures proper permissions when interacting with the YouTube API.
{% endhint %}

Navigate to **Customize > Theme Options > Google OAuth** and provide your **Google Client ID** and **Google Client Secret** keys.

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FZeYNYwhqhJyT7faHeXSn%2F5454723972.png?alt=media&#x26;token=5693d439-f66a-4504-9983-fd8e7923ca7d" alt=""><figcaption></figcaption></figure>

See "Implementing OAuth 2.0 Authorization" for further instructions <https://developers.google.com/youtube/v3/guides/authentication>

Your Google OAuth App must have "**YouTube Data API v3**" enabled for proper functionality.

#### Assign Capabilities <a href="#assign-capabilities" id="assign-capabilities"></a>

For detailed instructions on assigning capabilities, please refer to [content-capabilities](https://phpface.gitbook.io/streamtube/content-capabilities "mention")

1. Select the "**Post Type: YouTube Importers**".
2. Choose a specific user role to grant permissions to, or "All" to retrieve all roles.
3. Check the necessary capability checkboxes.

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FjsWTcSEqbBsoTQoILDxE%2F9465722085.png?alt=media&#x26;token=74c021b1-59ea-487e-bc60-c334cfeeb7a0" alt=""><figcaption><p>YouTube Importers Capabilities</p></figcaption></figure>

***

#### Create A YouTube API Key (deprecated) <a href="#api-key" id="api-key"></a>

Since version 4.x, creating an API key is no longer necessary, as authentication is now handled through OAuth. OAuth provides a more secure and user-friendly way for users to connect their accounts directly without manually entering API keys.&#x20;

{% embed url="<https://www.youtube.com/watch?v=uIw4iP_dvuY>" %}

***

#### **Manual Import** <a href="#manual-import" id="manual-import"></a>

{% embed url="<https://www.youtube.com/watch?v=KWM-u7irEyg>" %}

***

#### Auto Import Using Hosting Cronjob (deprecated) <a href="#hosting-cronjob" id="hosting-cronjob"></a>

***

Copy the CronTab URL of Importer and set it up in your Hosting Panel

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FWyvrr28Mw47oJSbS0aY7%2F7583692718.png?alt=media&#x26;token=853e3a3c-fcae-42d0-be30-30a7ef7642ff" alt=""><figcaption></figcaption></figure>

For example, with **DreamHost** hosting<br>

* [Creating a cron job in the panel](https://help.dreamhost.com/hc/en-us/articles/215088668-How-do-I-create-a-cron-job-)
* [Running a cron job from a URL with variables](https://help.dreamhost.com/hc/en-us/articles/215088668-How-do-I-create-a-cron-job-#url-with-variables)

**Command**

**wget** [**http://domain.com/youtube\_importer/my-music/?key=123456789**](http://domain.com/youtube_importer/my-music/?key=123456789)

OR

**curl '<http://domain.com/youtube\\_importer/my-music/?key=123456789>'**

***

#### Auto Import Using WP Control Plugin (deprecated) <a href="#wp-control" id="wp-control"></a>

* Install and Activate **WP Control** plugin <https://wordpress.org/plugins/wp-crontrol/>
* Navigate to **Tools > Cron Events > Add New**&#x20;

  <figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2F0FgDJNAE8NSe90EnodUW%2F1249188340.png?alt=media&#x26;token=92f25bbd-d277-41ae-b776-27ff1231038d" alt=""><figcaption></figcaption></figure>
* Choose and fill in the necessary fields and click the "Add Event" button.

  file\_get\_contents( 'your crontab url' );

<figure><img src="https://2226487161-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqVWDZMetj6mBqmoSajgK%2Fuploads%2FaXhsnk8d6CnsFax1aIPV%2F4267490109.png?alt=media&#x26;token=73f40c88-68e8-416a-b359-5cc117520a1b" alt=""><figcaption></figcaption></figure>

***

#### Filter Post Arguments

{% embed url="<https://gist.github.com/nttoanbrvt/55c59d43c3a848d6f264aab14c5e996c>" %}
Example code snippet to modify WP video post date based on YouTube-formatted date before inserting into the database.
{% endembed %}
