20 Dec 2015

Social Media Feed Blender

Web Development

api, PHP, social media

Nowadays most companies have one or more social media accounts and I'm often asked to embed this source of content into their websites. Here's a PHP class that fetches all the desired feeds, mixes them up and generates a uniform, cacheable source.

For now four social networks are available: Facebook, Twitter, Instagram and Youtube. In the case of Facebook, Twitter and Youtube, an application must be registered in order to get the needed client_id and app_secret credentials. The ones in the example are for demonstration purposes only and will expire soon.

Facebook applications can be registered here, Twitter applications here and Youtube applications here.

Usage example:

require 'FeedBlender.php';
$feed_blender = new FeedBlender(
$response_json = $feed_blender->getFeed(30);

Results in something like:

  "status": "success",
  "message": "",
  "data": [
      "source": "twitter",
      "username": "NASA",
      "id": 706291714785452032,
      "link": "",
      "timestamp": 1457228041,
      "created_time": "05 Mar 2016",
      "text": "After yrs of tests & development, scientific balloon is set to break flight duration record:",
      "image": ""
      "source": "facebook",
      "username": "MIT Media Lab",
      "id": "51320424738_10154093003709739",
      "link": "",
      "timestamp": 1457224511,
      "created_time": "05 Mar 2016",
      "text": "Celebrating the Invisible Cryptologists: The Digital Currency Initiative's Gina Vargas on the African-Americans who were instrumental to developing early cryptography from WWII through 1956."

Besides the benefit of simplification by abstracting all responses into a single collection, there's also a huge performance improvement from caching requests. When calling the APIs, all requests can take something like 10000 millisseconds -- while the access of cached content takes about 5 milliseconds. Furthermore, this prevents exceeding most API rate limits.

FeedBlender on GitHub