谷歌Oauth 2 PHP-谷歌日历

谷歌Oauth 2 PHP-谷歌日历,php,authentication,calendar,google-oauth,Php,Authentication,Calendar,Google Oauth,我尝试用谷歌日历制作一个应用程序。我正在使用此代码(已找到) ,但我有一些问题 <?php require_once 'google-api-php-client-master/src/Google/autoload.php'; require_once 'google-api-php-client-master/src/Google/Client.php'; require_once 'google-api-php-client-master/src/Google/Servic

我尝试用谷歌日历制作一个应用程序。我正在使用此代码(已找到) ,但我有一些问题

<?php  
require_once 'google-api-php-client-master/src/Google/autoload.php';   
require_once 'google-api-php-client-master/src/Google/Client.php';
require_once 'google-api-php-client-master/src/Google/Service/Calendar.php';  
//require_once 'CalendarHelper.php';  
session_start(); 
$client = new Google_Client();
$client->setApplicationName("name");
$client->setDeveloperKey("devkey");  
$client->setClientId('clientid');
$client->setClientSecret('cliendsecret');
$client->setRedirectUri('https://localhost/testGoogle/index.php');
$client->setAccessType('offline');   // Gets us our refreshtoken

$client->setScopes(array('https://www.googleapis.com/auth/calendar.readonly'));


//For loging out.
if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
}


// Step 2: The user accepted your access now you need to exchange it.
if (isset($_GET['code'])) {
    echo "test";
    $client->authenticate($_GET['code']);  
    $_SESSION['token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

// Step 1:  The user has not authenticated we give them a link to login    
if (!isset($_SESSION['token'])) {

    $authUrl = $client->createAuthUrl();

    print "<a class='login' href='$authUrl'>Connect Me!</a>";

}    
// Step 3: We have access we can now create our service
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
    print "<a class='logout' href='".$_SERVER['PHP_SELF']."?logout=1'>LogOut</a><br>";  

    $service = new Google_Service_Calendar($client);    
    $calendarList  = $service->calendarList->listCalendarList();;
    print_r($calendarList);
    while(true) {
        foreach ($calendarList->getItems() as $calendarListEntry) {
            echo $calendarListEntry->getSummary()."<br>\n";
        }
        $pageToken = $calendarList->getNextPageToken();
        if ($pageToken) {
            $optParams = array('pageToken' => $pageToken);
            $calendarList = $service->calendarList->listCalendarList($optParams);
        } else {
            break;
        }
    }
}
?>

当我点击“连接我!”按钮时,我选择我的google帐户,接受所需的权限,然后:

  • 如果我将https://localhost/testGoogle/index.php作为重定向URI,则出现错误:

    该网页不可用”,控制台中出现此错误:“加载资源失败:net::ERR\u连接被拒绝”

  • 如果我将http://localhost/testGoogle/index.php作为重定向URI,则出现php错误:

    致命错误:在C:\wamp\www\testGoogle\Google api php client master\src\Google\IO\Curl.php的第116行出现未捕获的异常“Google\u IO\u exception”,并显示消息“未能连接到accounts.Google.com端口443:连接被拒绝”

    (!)Google_IO_异常:无法连接到accounts.Google.com端口443:在第116行的C:\wamp\www\testGoogle\Google api php client master\src\Google\IO\Curl.php中拒绝连接

我的代码怎么了