Guides / YouTube API key

About ten minutes

A YouTube API key, so a tab can hold more than 15 videos

Without a key, YouTube's public feed hands out a channel's or playlist's newest fifteen videos and no more. With a key, DreamWidget asks YouTube directly and can load up to fifty per tab. The key is free, it is yours, and it never leaves your account.

Why the feed stops at fifteen

YouTube publishes a small public feed for every channel and playlist. It exists for RSS readers and it lists the newest fifteen entries, full stop. That is what a Video Showcase reads when it has no key, and it is why "Refresh videos" on a tab with no key never brings more than fifteen, and why the Rows setting tells you a tab is full at fifteen.

The YouTube Data API is the other door. It is the same data YouTube's own apps use, it needs a key so Google can see who is asking, and it can return fifty videos per page. DreamWidget uses it only to read: titles, thumbnails, dates and view counts of public videos. It never posts, never touches your channel, and never needs your password.

Getting the key

  1. Sign in to Google Cloud. Open console.cloud.google.com and sign in with any Google account. It does not have to be the account that owns the YouTube channel; any account can hold a key that reads public videos. The first visit asks you to agree to Google Cloud's terms; there is no card to enter for this.
  2. Make a project. At the top of the page, next to the Google Cloud logo, there is a project picker. Click it, then New project. Name it anything, "DreamWidget" is fine, leave the organization as it is, and click Create. Wait for the notification that it is ready, then make sure the picker shows your new project.
  3. Turn on the YouTube Data API. Open this link, which goes straight to the YouTube Data API v3 page in the library, check the project name at the top, and click Enable. It takes a few seconds.
  4. Create the key. In the left menu open APIs & Services, then Credentials. Click + Create credentials at the top and choose API key. A box shows the new key: a string of about forty letters and digits starting with AIza. Copy it now. You can always find it again on the Credentials page.
  5. Restrict it to YouTube. In the same box click Edit API key (or click the key's name on the Credentials page). Under API restrictions choose Restrict key, tick YouTube Data API v3 only, and Save. Now the key can do nothing else even if it leaks. The Application restrictions section above it can stay on None.
What it costs. Nothing. Google gives every project 10,000 "units" a day for this API, and loading a tab of fifty videos costs a few units. Refreshing every tab of a busy widget a hundred times a day would not get near the limit. Your visitors never spend a unit: the widget publishes its list of videos to the CDN and the players come from YouTube itself, so views of the widget do not touch this key, however many there are. There is no card on file and nothing that can be charged.

Pasting it into DreamWidget

  1. Open your Video Showcase in the dashboard. Go to the Settings tab.
  2. Paste the key into the editor. It goes in the YouTube Data API key box under Video source. It saves as you type, privately to your account: it is stored on our side against your sign-in, never published with the widget, and never visible to anyone who views the widget.
  3. Decide how many videos a tab may hold. Use Max videos per tab in the same card, up to fifty.
  4. Press Refresh videos, at the top. Every tab reloads through the API. A tab that had fifteen now has up to your maximum.
  5. Press Publish changes. The button is at the top right. The videos loaded are what the widget shows; the key is not part of the published widget.

Keeping it safe

A key restricted to the YouTube Data API can only read public YouTube data, which is public anyway. Even so: do not paste it into forums or screenshots, and if you ever think it has leaked, go back to the Credentials page, delete it, create a new one, and paste the new one into DreamWidget. The old one stops working the moment it is deleted.

DreamWidget stores the key against your account in a private record that only your sign-in can read. It is used from your browser when you add a source or press Refresh, and it is not included in the widget that is published to your site.

Questions

"The API key is not valid" when I refresh

Almost always one of three things: the YouTube Data API was not enabled on the project the key belongs to (step 3), the key was restricted to a different API (step 5), or a character was lost in the copy. Check the key on the Credentials page against what is pasted.

"Quota exceeded"

The daily 10,000 units Google gives your key were used up refreshing video lists, which takes deliberate effort. The widget on your site is unaffected: it keeps showing the last list it published, to any number of visitors. The allowance resets at midnight Pacific time. If it happens without effort, another app is using the same key; make a separate key for DreamWidget.

Does the key give DreamWidget access to my channel?

No. A key is not a sign-in. It can read public videos, the same ones anyone can see on YouTube, and nothing private. Managing your channel would need you to sign in with Google and grant permission, which DreamWidget never asks for.

Can I use one key for several widgets?

Yes. The key belongs to your DreamWidget account, and every Video Showcase you own uses it.

Vimeo, Twitch and TikTok

None of them needs a key from you. See the sources guide.