SilverStripe Social Feed
Combine social media posts from Facebook, Twitter and Instagram into a single feed.
Each feed is available separately also., (*1)
Installation
composer require isaacrankin/silverstripe-social-feed
, (*2)
Usage
<% include SocialFeed %>
, (*3)
Alternatively you can call the SocialFeed
method directly like so:, (*4)
<div class="social-feed">
<ol>
<% loop SocialFeed %>
<li>
<a href="$URL" target="_blank">
<h4>Type: $Type</h4>
<p>Created: $Created</p>
<p>User: $UserName</p>
<p><img src="$Image" /></p>
<p>$Content</p>
</a>
</li>
<% end_loop %>
</ol>
</div>
The posts are ordered from newest to oldest., (*5)
Within the SocialFeed
control loop the following values are available:, (*6)
-
$URL
- a URL for the social media post
-
$Type
- the type of post, either "facebook", "twitter" or "instagram"
-
$Created
- the creation/posted date of the post
-
$UserName
- the user who made the post
-
$Image
- the main image for the post
-
$Data
- all of the data for a single post in the original structure returned from the API's. Read documentation for the API's to see what's available.
Caching
All SocialMediaProvider::getFeed() calls are cached for 15 minutes and can be cleared either in the CMS or by appending ?socialfeedclearcache=1 in developer mode., (*7)
There is also a SocialFeedCacheTask that you can setup as a cronjob on your server to ensure that the end-user never has to wait for your server to make its API calls to Facebook, Twitter, etc and update the various social feed caches., (*8)
Alternatively, if you're using the QueuedJobs module, this process will be handled automatically for you, as a queued job is setup to update the cache every 10 minutes., (*9)
Requirements
SilverStripe 4 or newer, (*10)
The Twitter data is a collection of the most recent Tweets posted by the user.
The following API endpoint is used https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi
, (*11)
Twitter API documentation for user timeline, (*12)
Credentials
You'll need to create a Twitter app here https://apps.twitter.com/app/, (*13)
Facebook
The Facebook data returned is the most recent posts for a given Facebook Page.
The following API endpoint is used https://graph.facebook.com/PAGE_ID/feed?access_token=ACCESS_TOKEN
, (*14)
Facebook API documentation, (*15)
Credentials
To get the necessary Facebook API credentials you'll need to create a Facebook App., (*16)
Instagram
The most recent media published for a user.
The following API endpoint is used https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS_TOKEN
Instagram API documentation for resent user media, (*17)
Credentials
To get the necessary Instagram API credentials you'll need to create an Instagram Client., (*18)
You'll need to add the correct redirect URI in the settings for the Instagram App, such as http://yoursite.com/admin/social-feed/SocialFeedProviderInstagram/, (*19)