无法使用 google-api-php-client 库对 UserInfo 服务进行身份验证


Can not authenticate with UserInfo service with google-api-php-client library

我正在使用google-api-php-client库测试OAuth2服务,以使用Google帐户访问登录用户的用户信息。代码取自示例/用户信息/索引.php几乎没有变化来应对我的主机。运行示例时,它通过谷歌登录表单传递。当它回到我的网站时,抛出了一个异常,如下所示。

Fatal error:  Uncaught exception 'apiIOException' with message 'HTTP Error: (0) couldn't connect to host' in /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/io/apiCurlIO.php:120
Stack trace:
#0 /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/io/apiCurlIO.php(46): apiCurlIO->makeRequest(Object(apiHttpRequest))
#1 /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/io/apiREST.php(55): apiCurlIO->authenticatedRequest(Object(apiHttpRequest))
#2 /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/service/apiServiceResource.php(151): apiREST::execute(Object(apiServiceRequest))
#3 /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/contrib/apiPlusService.php(207): apiServiceResource->__call('get', Array)
#4 /home/ztbmwjhd/public_html/apis/at/googleplus/google-plus-access.php(40): PeopleServiceResource->get('me')
#5 /home/ztbmwjhd/public_html/apis/at/googleplus/index.php(2): include_once('/home/ztbmwjhd/...')
#6 {main}
  throw in /home/ztbmwjhd/public_html/apis/at/googleplus/google-api-php-client/src/io/apiCurlIO.php on line 120

谢谢你的帮助

错误"HTTP 错误:(0) 无法连接到主机"通常意味着您的服务器和 Google 之间存在问题。您是否通过代理进行连接?

此外,请尝试从命令行运行"curl https://www.googleapis.com/discovery/v1/apis"。