本文介绍了致命错误:未捕获的异常"Google_IOException"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使php代码用于列出Google用户的用户.我遵循了 youtube教程,并尝试了,但我仍然收到这个烦人的错误当我调用authenticate方法时:

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

这是我的PHP代码:

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

谢谢.

推荐答案

您的服务器似乎在连接到www.googleapis.com时出现问题.您将需要检查网络连接.

It looks like your server is having issues connecting to www.googleapis.com. You will need to check your network connection.

查看您是否能够访问 https://www.googleapis.com/discovery /v1/apis .

如果使用代理,则需要将curl_setopt($ch, CURLOPT_PROXY, 'your-proxy-settings');添加到Google_CurlIO.php.

If you are using a proxy then you need to add curl_setopt($ch, CURLOPT_PROXY, 'your-proxy-settings'); to Google_CurlIO.php.

curl_setopt($ch, CURLOPT_USERAGENT, $request->getUserAgent());

这篇关于致命错误:未捕获的异常"Google_IOException"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:21