2013-03-28 203 views
0

我正在努力使工作成为列出谷歌用户用户的php代码。我按照一个youtube tutorial和tryed在this one提出的解决方案,但是,当我打电话认证方法中我仍然得到这个恼人的错误:致命错误:未捕获异常'Google_IOException'

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

?> 

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

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

谢谢。

回答

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());

+0

事实上,这是代理。非常感谢。 – restricteur 2013-07-25 10:11:18

相关问题