嗨,我在尝试为非 google plus 帐户实施 google plus Api 时遇到问题。我遵循了谷歌开发者网站上的代码示例。在尝试对用户进行身份验证时,我注意到如果您取消/拒绝创建 google plus 个人资料,它会给出一个带有 URL“ https://plus.google.com/up?continue= ”的空白屏幕。如果我重新加载页面,我将提供创建 google plus 配置文件对话框,并在取消时再次显示空白屏幕。我希望能够让用户取消并返回到我的网站。
<?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>";
?>