MENU

During a recent site build, we were frustrated that there weren’t any simple Google Plus recent post feeds out there. So, we decided to create one ourselves! We are such a loving bunch of peeps that we thought we’d share it with you guys too.

Firstly, you need to log into (and sign in if you haven’t already) the Google Developers API console https://code.google.com/apis/console. Set up a new API project for our Google Plus feed and get a shiny new Developer Key.

You also need to download Google_Client.php and save it locally on your site:
https://code.google.com/p/google-api-php-client/source/browse/trunk/src/Google_Client.php

And do the same for Google_PlusService.php:
https://code.google.com/p/google-api-php-client/source/browse/trunk/src/contrib/Google_PlusService.php

Then add the following PHP code in place where you want the latest post widget:

<?php
require_once(‘PATH_TO/Google_Client.php’);
require_once(‘PATH_TO/Google_PlusService.php’);

$client = new Google_Client();

$client->setDeveloperKey(“ENTER_YOUR_GOOGLE_DEV_KEY_HERE”);
$plus = new Google_PlusService($client);
$optParams = array(‘maxResults’ => 1);
$activities = $plus->activities->listActivities(“ENTER_YOUR_G+_ID_HERE”, “public”, $optParams);

$output = ”;
foreach($activities[‘items’] as $activity){
$output .= ‘<p>’ . $activity[‘title’] . ‘</p>’;
}
#return print_r($activities[‘items’], true);
return $output;
?php>

This just prints out the latest post in a <p> tag. You can change the amount of posts it returns by changing the number in (‘maxResults’ => 1);.

Here’s a simple example of how we have used it in a widget on a website we have recently developed:

Simple as that!

As a highly trained team of web developers, Adao* are market leaders in providing any custom programming or website development. Feel free to contact us now to discuss your requirements.