问题
I am trying to make work a php code for listing the users of a google user. I have followed a youtube tutorial and tryed the solutions proposed in this one But I still get this annoying error when I call the authenticate method :
Fatal error: Uncaught exception 'Google_IOException' with message 'HTTP Error: (0) couldn't connect to host' in D:\xampp\htdocs\yac\proxy\lib\google-api-client\io\Google_CurlIO.php:128 Stack trace: #0 D:\xampp\htdocs\yac\proxy\lib\google-api-client\auth\Google_OAuth2.php(103): Google_CurlIO->makeRequest(Object(Google_HttpRequest)) #1 D:\xampp\htdocs\yac\proxy\lib\google-api-client\Google_Client.php(131): Google_OAuth2->authenticate(Array, NULL) #2 D:\xampp\htdocs\yac\proxy\contacts.php(36): Google_Client->authenticate() #3 {main} thrown in D:\xampp\htdocs\yac\proxy\lib\google-api-client\io\Google_CurlIO.php on line 128
here is my PHP code :
<?php
session_start();
require_once 'lib/google-api-client/Google_Client.php';
$client = new Google_Client();
$client->setApplicationName("Contactoos");
$client->setClientId('*************************************');
$client->setClientSecret('*********************************');
$client->setScopes(array('http://www.google.com/m8/feeds'));
$client->setRedirectUri('http://localhost/yac/proxy/contacts.php');
$client->setAccessType('online');
if(isset($_GET['code']))
{
echo "here";
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('location:http://localhost/yac/proxy/contacts.php');
}
if(!isset($_SESSION['token']))
{
$url = $client->createAuthUrl();
?>
<a href="<?=$url;?>"> List google contacts</a>
<?php
}
else
{
$client->setAccessToken($_SESSION['token']);
}
?>
As I said, I tried the solutions proposed in the second tutorial but in vain.
Does anyone know how to fix this problem ?
Thanks.
回答1:
It looks like your server is having issues connecting to www.googleapis.com. You will need to check your network connection.
See if you're able to visit https://www.googleapis.com/discovery/v1/apis from that machine.
If you are using a proxy then you need to add curl_setopt($ch, CURLOPT_PROXY, 'your-proxy-settings');
to Google_CurlIO.php
.
I've added it on line 111, after curl_setopt($ch, CURLOPT_USERAGENT, $request->getUserAgent());
来源:https://stackoverflow.com/questions/15679393/fatal-error-uncaught-exception-google-ioexception