示例#1
0
// your cache file, make sure it's writable
$cacheFile = '/tmp/gplus-cache';
// 30 minutes Cache Time
$cacheTime = 1800;
// a (in this case my) Google Plus ID
$googlePlusID = '113799277735885972934';
// your Google+ API key, obtain your's here https://code.google.com/apis/console/b/0/
$key = 'XXX';
// your Google+ Activity Stream, get more info: https://developers.google.com/+/api/latest/activities
$url = 'https://www.googleapis.com/plus/v1/people/' . $googlePlusID . '/activities/public?alt=json&pp=1&key=';
// got cachefile?
$lmod = @filemtime($cacheFile);
if (!isset($_GET['purgeCache']) && $lmod && filesize($cacheFile) && time() - $lmod < $cacheTime) {
    $content = file_get_contents($cacheFile);
} else {
    $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');
}
// for debugging:
#print_r($gplus); exit;
// Output RSS feed
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
示例#2
0
    } else {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $content = curl_exec($ch);
        curl_close($ch);
    }
    return $content;
}
// got cachefile?
$lmod = @filemtime($cacheFile);
if (!isset($_GET['purgeCache']) && $lmod && filesize($cacheFile) && time() - $lmod < $cacheTime) {
    $content = file_get_contents($cacheFile);
} else {
    $content = fetchAPI($url);
    if ($content) {
        file_put_contents($cacheFile, $content);
    }
}
if (!$content) {
    die('Failed to load G+ data');
}
$content = substr($content, 5);
$content = str_replace("\n", "", $content);
$content = str_replace(',,', ',"",', $content);
$content = str_replace(',,', ',"",', $content);
$json = json_decode($content, true);
if (!isset($json[0]) || !isset($json[0][1]) || !isset($json[0][1][0])) {
    die("json wasn't decoded");
}