Google Plus Api可创建公开个人资料

时间:2013-10-30 20:24:55

标签: google-plus

嗨我试图为非谷歌加帐户实施谷歌加Api的问题。我关注了谷歌开发者网站的代码示例。在尝试对用户进行身份验证时,我注意到如果您取消/拒绝创建Google Plus配置文件,则会显示一个带有网址的空白屏幕" https://plus.google.com/up?continue="。如果我重新加载页面,我将给出创建谷歌加配置文件对话框,并在再次取消时显示空白屏幕。我希望能够让用户取消并返回我的网站。

<?php
require_once ('includes/utilities.inc.php');


require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_PlusService.php';



$client = new Google_Client();
$client->setApplicationName("Google Plus PHP Starter Application");
// Visit https://code.google.com/apis/console?api=plus to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
$client->setClientId('******************');
$client->setClientSecret('****************');
$client->setRedirectUri("***********************");
$client->setDeveloperKey('***********************');

$plus = new Google_PlusService($client);

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
    $activities = $plus->activities->listActivities('me', 'public');
    print 'Your Activities: <pre>' . print_r($activities, true) . '</pre>';

    // We're not done yet. Remember to update the cached access token.
    // Remember to replace $_SESSION with a real database or memcached.
    $_SESSION['token'] = $client->getAccessToken();
} else {
    $authUrl = $client->createAuthUrl();
    print "<a href='$authUrl'>Connect Me!</a>";
}
echo "<pre>";
print_r($user_google);
print_r( $_SESSION['token']);
echo"</pre>";

?>

0 个答案:

没有答案