аутентификация — Google Oauth 2 Google календарь

Я пытаюсь сделать заявку с помощью Календаря Google. Я использую этот код (найдено Вот )
Но у меня есть некоторые проблемы.

<?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_CONNECTION_REFUSED

  • Если я поставлю HTTP: //localhost/testGoogle/index.php в качестве URI перенаправления, у меня ошибка PHP:

    Неустранимая ошибка: необработанное исключение «Google_IO_Exception» с сообщением «Не удалось соединиться с портом account.google.com 443: соединение отклонено» в C: \ wamp \ www \ testGoogle \ google-api-php-client-master \ src \ Google \ IO \ Curl.php в строке 116

    (!) Google_IO_Exception: не удалось подключиться к порту account.google.com 443: соединение отклонено в C: \ wamp \ www \ testGoogle \ google-api-php-client-master \ src \ Google \ IO \ Curl.php в сети 116

Что не так с моим кодом?

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector