0

我正在尝试制作一个用于列出谷歌用户的用户的 php 代码。我遵循了一个youtube 教程并尝试了这个中提出的解决方案 但是当我调用验证方法时我仍然遇到这个烦人的错误:

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']);
}

?>

正如我所说,我尝试了第二个教程中提出的解决方案,但徒劳无功。

有谁知道如何解决这个问题?

谢谢。

4

1 回答 1

3

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

查看您是否能够从该计算机访问https://www.googleapis.com/discovery/v1/apis 。

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

我在第 111 行添加了它,之后curl_setopt($ch, CURLOPT_USERAGENT, $request->getUserAgent());

于 2013-07-04T12:41:31.113 回答