Fetch GooglePlus Feeds using PHP

By August 15, 2015PHP

Fetch GooglePlus Feeds to your website using PHP

<?php function fetchAPI($url) {

 $content = '';

 if (ini_get('allow_url_fopen') == true) {
  $content = file_get_contents($url);
 }
 else {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url . $key);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $content = curl_exec($ch);
  curl_close($ch);
 }
 return $content;
}


// Google+ ID
$googlePlusID = 'YOUR ID';
$url = "https://plus.google.com/YOUR ID/posts";
// Google+ API key
$key = 'DEVELOPER KEY';

$url = 'https://www.googleapis.com/plus/v1/people/' . $googlePlusID . '/activities/public?alt=json&pp=1&key=';

$content = fetchAPI($url . $key);

if ($content)
 file_put_contents($cacheFile, $content);
if (!$content)
 die('Failed to load G+ data');
$gplus = json_decode($content);

if (!$gplus)
 die('Failed to decode G+ data');
echo "
<pre&gt;";
print_r($gplus);
die;

Pankaj Singh Sugara

Author Pankaj Singh Sugara

Experienced Software Engineer with a demonstrated history of working in the marketing and advertising industry. Skilled in SQL, Web Applications, PHP, WordPress, and Joomla. Strong engineering professional with a B-TECH focused in Information Technology from JCDM College of Engineering Sirsa, Haryana.

More posts by Pankaj Singh Sugara