Php 消息:HTTP错误:(0)无法连接到accounts.google.com端口80:连接超时

Php 消息:HTTP错误:(0)无法连接到accounts.google.com端口80:连接超时,php,codeigniter,curl,port,google-login,Php,Codeigniter,Curl,Port,Google Login,我正在尝试使用带有codeigniter框架的google登录。 它以前工作得很好。现在,相同的代码给出了下面的错误消息。 我怎样才能解决这个问题 Localhost显示以下错误 An uncaught Exception was encountered Type: apiIOException Message: HTTP Error: (0) Unsupported proxy scheme for 'https://accounts.google.com/o/oauth2/token'

我正在尝试使用带有codeigniter框架的google登录。 它以前工作得很好。现在,相同的代码给出了下面的错误消息。 我怎样才能解决这个问题

Localhost显示以下错误

An uncaught Exception was encountered

Type: apiIOException

Message: HTTP Error: (0) Unsupported proxy scheme for 'https://accounts.google.com/o/oauth2/token'

Filename: application\third_party\google-login-api\io\apiCurlIO.php
Type: apiIOException

Message: HTTP Error: (0) Failed to connect to accounts.google.com port 80: Connection timed out

Filename: application/third_party/google-login-api/io/apiCurlIO.php
在服务器上托管后,它显示以下错误

An uncaught Exception was encountered

Type: apiIOException

Message: HTTP Error: (0) Unsupported proxy scheme for 'https://accounts.google.com/o/oauth2/token'

Filename: application\third_party\google-login-api\io\apiCurlIO.php
Type: apiIOException

Message: HTTP Error: (0) Failed to connect to accounts.google.com port 80: Connection timed out

Filename: application/third_party/google-login-api/io/apiCurlIO.php
下面是我的curl脚本

 $ch = curl_init();
    curl_setopt($ch, CURLOPT_PROXY, $request->getUrl()); //your proxy url
    curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number
    curl_setopt_array($ch, self::$DEFAULT_CURL_PARAMS);
    curl_setopt($ch, CURLOPT_URL, $request->getUrl());
    if ($request->getPostBody()) {
      curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPostBody());
    }

    $requestHeaders = $request->getRequestHeaders();
    if ($requestHeaders && is_array($requestHeaders)) {
      $parsed = array();
      foreach ($requestHeaders as $k => $v) {
        $parsed[] = "$k: $v";
      }
      curl_setopt($ch, CURLOPT_HTTPHEADER, $parsed);
    }

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

    $respData = curl_exec($ch);

    // Retry if certificates are missing.
    if (curl_errno($ch) == CURLE_SSL_CACERT) {
      error_log('SSL certificate problem, verify that the CA cert is OK.'
        . ' Retrying with the CA cert bundle from google-api-php-client.');
      curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem');
      $respData = curl_exec($ch);
    }

    $respHeaderSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $respHttpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curlErrorNum = curl_errno($ch);
    $curlError = curl_error($ch);
    curl_close($ch);
    if ($curlErrorNum != CURLE_OK) {
      throw new apiIOException("HTTP Error: ($respHttpCode) $curlError");
    }

如何解决这个问题

我在codeignator中有一个使用gmail登录的代码。您可以更改代码并尝试使用以下4个文件。我相信这段代码对你有帮助

文件1: config/googleplus.php:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
$config['googleplus']['application_name'] = 'abc';
$config['googleplus']['client_id']        = '#######';
$config['googleplus']['client_secret']    = '#######';
$config['googleplus']['redirect_uri']     = 'abc.com/social_login';

$config['googleplus']['api_key']          = '######';
$config['googleplus']['scopes']           = array();
?>
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Googleplus {

   public function __construct() {

    $CI =& get_instance();
    $CI->config->load('googleplus');

    require APPPATH .'third_party/google-login-api/apiClient.php';
    require APPPATH .'third_party/google-login-api/contrib/apiOauth2Service.php';



    $this->client = new apiClient();
    $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
    $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
    $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
    $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
    $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));
    $this->client->setScopes($CI->config->item('scopes', 'googleplus'));
    $this->client->setAccessType('online');
    $this->client->setApprovalPrompt('auto');
    $this->oauth2 = new apiOauth2Service($this->client);

}

public function loginURL() {
    return $this->client->createAuthUrl();
}

public function getAuthenticate() {
    return $this->client->authenticate();
}

public function getAccessToken() {
    return $this->client->getAccessToken();
}

public function setAccessToken() {
    return $this->client->setAccessToken();
}

public function revokeToken() {
    return $this->client->revokeToken();
}

public function getUserInfo() {
    return $this->oauth2->userinfo->get();
}

}
?>

文件2: 库/Googleplus.php:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
$config['googleplus']['application_name'] = 'abc';
$config['googleplus']['client_id']        = '#######';
$config['googleplus']['client_secret']    = '#######';
$config['googleplus']['redirect_uri']     = 'abc.com/social_login';

$config['googleplus']['api_key']          = '######';
$config['googleplus']['scopes']           = array();
?>
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Googleplus {

   public function __construct() {

    $CI =& get_instance();
    $CI->config->load('googleplus');

    require APPPATH .'third_party/google-login-api/apiClient.php';
    require APPPATH .'third_party/google-login-api/contrib/apiOauth2Service.php';



    $this->client = new apiClient();
    $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
    $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
    $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
    $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
    $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));
    $this->client->setScopes($CI->config->item('scopes', 'googleplus'));
    $this->client->setAccessType('online');
    $this->client->setApprovalPrompt('auto');
    $this->oauth2 = new apiOauth2Service($this->client);

}

public function loginURL() {
    return $this->client->createAuthUrl();
}

public function getAuthenticate() {
    return $this->client->authenticate();
}

public function getAccessToken() {
    return $this->client->getAccessToken();
}

public function setAccessToken() {
    return $this->client->setAccessToken();
}

public function revokeToken() {
    return $this->client->revokeToken();
}

public function getUserInfo() {
    return $this->oauth2->userinfo->get();
}

}
?>

文件3: controller/login.php:

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {

function __construct() {
    parent::__construct();
    $this->load->library('Googleplus');
}

    $data['login_url'] = $this->googleplus->loginURL();
    $this->load->view('user_login', $data);
}
?>
<a href="<?php echo $login_url;?>">Login with google</a>

文件4: views/login.php:

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {

function __construct() {
    parent::__construct();
    $this->load->library('Googleplus');
}

    $data['login_url'] = $this->googleplus->loginURL();
    $this->load->view('user_login', $data);
}
?>
<a href="<?php echo $login_url;?>">Login with google</a>

我在Codeignor中有一个使用gmail登录的代码。您可以更改代码并尝试使用以下4个文件。我相信这段代码对你有帮助

文件1: config/googleplus.php:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
$config['googleplus']['application_name'] = 'abc';
$config['googleplus']['client_id']        = '#######';
$config['googleplus']['client_secret']    = '#######';
$config['googleplus']['redirect_uri']     = 'abc.com/social_login';

$config['googleplus']['api_key']          = '######';
$config['googleplus']['scopes']           = array();
?>
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Googleplus {

   public function __construct() {

    $CI =& get_instance();
    $CI->config->load('googleplus');

    require APPPATH .'third_party/google-login-api/apiClient.php';
    require APPPATH .'third_party/google-login-api/contrib/apiOauth2Service.php';



    $this->client = new apiClient();
    $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
    $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
    $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
    $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
    $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));
    $this->client->setScopes($CI->config->item('scopes', 'googleplus'));
    $this->client->setAccessType('online');
    $this->client->setApprovalPrompt('auto');
    $this->oauth2 = new apiOauth2Service($this->client);

}

public function loginURL() {
    return $this->client->createAuthUrl();
}

public function getAuthenticate() {
    return $this->client->authenticate();
}

public function getAccessToken() {
    return $this->client->getAccessToken();
}

public function setAccessToken() {
    return $this->client->setAccessToken();
}

public function revokeToken() {
    return $this->client->revokeToken();
}

public function getUserInfo() {
    return $this->oauth2->userinfo->get();
}

}
?>

文件2: 库/Googleplus.php:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
$config['googleplus']['application_name'] = 'abc';
$config['googleplus']['client_id']        = '#######';
$config['googleplus']['client_secret']    = '#######';
$config['googleplus']['redirect_uri']     = 'abc.com/social_login';

$config['googleplus']['api_key']          = '######';
$config['googleplus']['scopes']           = array();
?>
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Googleplus {

   public function __construct() {

    $CI =& get_instance();
    $CI->config->load('googleplus');

    require APPPATH .'third_party/google-login-api/apiClient.php';
    require APPPATH .'third_party/google-login-api/contrib/apiOauth2Service.php';



    $this->client = new apiClient();
    $this->client->setApplicationName($CI->config->item('application_name', 'googleplus'));
    $this->client->setClientId($CI->config->item('client_id', 'googleplus'));
    $this->client->setClientSecret($CI->config->item('client_secret', 'googleplus'));
    $this->client->setRedirectUri($CI->config->item('redirect_uri', 'googleplus'));
    $this->client->setDeveloperKey($CI->config->item('api_key', 'googleplus'));
    $this->client->setScopes($CI->config->item('scopes', 'googleplus'));
    $this->client->setAccessType('online');
    $this->client->setApprovalPrompt('auto');
    $this->oauth2 = new apiOauth2Service($this->client);

}

public function loginURL() {
    return $this->client->createAuthUrl();
}

public function getAuthenticate() {
    return $this->client->authenticate();
}

public function getAccessToken() {
    return $this->client->getAccessToken();
}

public function setAccessToken() {
    return $this->client->setAccessToken();
}

public function revokeToken() {
    return $this->client->revokeToken();
}

public function getUserInfo() {
    return $this->oauth2->userinfo->get();
}

}
?>

文件3: controller/login.php:

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {

function __construct() {
    parent::__construct();
    $this->load->library('Googleplus');
}

    $data['login_url'] = $this->googleplus->loginURL();
    $this->load->view('user_login', $data);
}
?>
<a href="<?php echo $login_url;?>">Login with google</a>

文件4: views/login.php:

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Login extends CI_Controller {

function __construct() {
    parent::__construct();
    $this->load->library('Googleplus');
}

    $data['login_url'] = $this->googleplus->loginURL();
    $this->load->view('user_login', $data);
}
?>
<a href="<?php echo $login_url;?>">Login with google</a>


@DanielStenberg您能看看更新的问题吗?当我将文件上传到服务器时,错误消息更改为“未能连接到accounts.google.com端口80”。就是它说的意思。curl无法从该计算机连接到主机“accounts.google.com”上的TCP端口80。由于网络设置、防火墙或其他原因。@DanielStenberg那么我如何检查服务器上是否有防火墙?还是什么阻止了我的请求?@DanielStenberg你能看看更新的问题吗?当我将文件上传到服务器时,错误消息更改为“未能连接到accounts.google.com端口80”。就是它说的意思。curl无法从该计算机连接到主机“accounts.google.com”上的TCP端口80。由于网络设置、防火墙或其他原因。@DanielStenberg那么我如何检查服务器上是否有防火墙?或者是什么阻止了我的请求?