Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

YouTubeFeed - Automatically syncs your YouTube videos with your SilverStripe site


Go to End


1069 Views

Avatar
Olliepop

Community Member, 5 Posts

1 September 2015 at 2:44pm

Edited: 01/09/2015 3:09pm

Hi all,

YouTubeFeed requests videos from an authenticated YouTube 'My Uploads' feed and converts them into YouTubeVideo DataObjects.

https://github.com/Little-Giant/silverstripe-youtubefeed

Features:
- Configurable auto-update interval (disabled by default)
- CLI task YouTubeFeedTask: "framework/sake YouTubeFeedTask flush=all"
- Stores video information into YouTubeVideo DataObject.

Installation requires creating an application in the Google Developers Console then copying and pasting the api key & secret into the Settings/YouTube tab in your CMS.

Example of using the onAfterCreate hook:

<?php

/**
 * Class YouTubeFeedExtension
 *
 * Decorates YouTubeFeed from silverstripe-youtubefeed to create a blog post for every YouTube video.
 */
class YouTubeFeedExtension extends DataExtension
{

    /**
     * Create a new BlogPost when a new YouTube video is found in the connected accounts YouTube playlists/"My Uploads" feed
     * Sets the PublishDate of the BlogPost to the date the video was published on YouTube
     *
     * @param YouTubeVideo $videoObject
     */
    public function onAfterCreate(YouTubeVideo $videoObject)
    {
        $blogPost = new BlogPost();
        $blogPost->Title = $videoObject->Title;
        $blogPost->YouTubeVideoID = $videoObject->ID;
        $blogPost->ParentID = Blog::get()->first()->ID;
        $blogPost->PublishDate = $videoObject->Published;
        $blogPost->write();
        $blogPost->publish("Live", "Stage");
    }

}