<?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>";
print_r($gplus);
die;
No comments:
Post a Comment