Forum

Thread tagged as: Question, Field-Types

YouTube videos

Hi, I've installed the add-on to perch/addons/fieldtypes/youtube/youtube.class.php and curl is enabled. I have created the API key and added the following to post.html.

<perch:blog id="video" type="youtube" label="YouTube video URL" output="embed" width="800" order="4" />

I can add the YouTube to a post in admin but I can't see the video when the viewing post on the site. I've saved all content.

Any ideas? Thanks

Jon H

Jon H 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you get on your site?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can we also see your Diagnostics Report?

Jon H

Jon H 0 points

Hi Drew, everything else added to the post through the admin is displayed. Just no Youtube video.

Rachel, here's the diagnostics report...

Perch: 2.8.18, PHP: 5.4.45, MySQL: 5.5.50, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.18), assets (2.8.18), categories (2.8.18), perch_blog (4.6), perch_forms (1.8.3), perch_members (1.2), perch_twitter (3.5.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', 'perch_twitter', 'perch_members' );
PERCH_LOGINPATH: /cms
PERCH_PATH: /home/*******/public_html/cms
PERCH_CORE: /home/*******/public_html/cms/core
PERCH_RESFILEPATH: /home/*******/public_html/cms/resources
Image manipulation: GD Imagick
PHP limits: Max upload 16M, Max POST 8M, Memory: 256M, Total max file upload: 8M
Resource folder writeable: Yes
DOCUMENT_ROOT: /home/*******/public_html
HTTP_HOST: *******
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you remove output="embed" what do you get?

Jon H

Jon H 0 points

The URL of the YouTube video is displayed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great.

What does output="player" give you?

Jon H

Jon H 0 points

Just the same Drew. Outputs the URL of the video.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you turn on debug, and then submit your content and let me know what it outputs? There should be an orange section with the YouTube API response.

Jon H

Jon H 0 points

Yes, here it is:

{ "error": { "errors": [ { "domain": "usageLimits", "reason": "ipRefererBlocked", "message": "The referrer null does not match the referrer restrictions configured on your API key. Please use the API Console to update your key restrictions.", "extendedHelp": "https://console.developers.google.com/apis/credentials?project=*******" } ], "code": 403, "message": "The referrer null does not match the referrer restrictions configured on your API key. Please use the API Console to update your key restrictions." } }
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's your answer - you'll need to check your API key.

Jon H

Jon H 0 points

I've checked the API key, generated a new one and updated the config file. Can't see anywhere on the Google API manager that has referrer restrictions? So there's nothing wrong with the post.html file?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, the issue is way before that - Perch can't get the information back from the API due to the above error.

Jon H

Jon H 0 points

Okay, strange. I'm now getting the iframe code displayed on the post and not the URL as before so it must be getting something back from API?

<iframe width="640" height="360" src="//www.youtube.com/embed/*******" frameborder="0" allowfullscreen></iframe>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Has the message in debug changed? That iframe can be deduced directly from your input.

Jon H

Jon H 0 points

It has yes. No longer returning an error but was still showing the iframe code on my post. Changed the post.html file to:

<perch:blog id="video" type="youtube" label="YouTube video URL" output="embed" width="800" order="4" />

and it works!

Is there a way to detect if there is a video associated with the post in a similar way to the <perch:if exists="image"> for images?

Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:if exists="video"> should work.

Jon H

Jon H 0 points

Of course! Thanks for you help Drew.