Part of my code is:
try {
$client = new Google_Client();
$client->setAuthConfig($credentials_file);
$client->setAccessType("offline");
$client->setIncludeGrantedScopes(true);
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
}catch(GuzzleHttp\Exception\ConnectException $e){
Connector::handleException($e); //just print $e->getMessage(); and die();
}catch(\Exception $e){
Connector::handleException($e); //just print $e->getMessage(); and die();
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$connector = Connector::init($client);
require_once "views/index.php";
} else {
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
in views/index.php
i just get locations and print them out.
i run my 'app' with php -S localhost:8000
Almost everything is ok, because some time to time ive got error:
cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to mybusiness.googleapis.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
and
cURL error 35: OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to oauth2.googleapis.com:443 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I need refresh site couple times till everything back to normal. Few days ago everything was fine. Sometimes it start working after first refresh, sometimes it take 5 minutes.
Why? Can I somehow fix it?
It seems that Google API have problems with curl with IPv6, so in file:
vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php
about line 40 I've added:
curl_setopt($easy->handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
and it resolved problem!