我正在尝试使用带有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
下面是我的卷曲脚本
$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");
}
如何解决这个问题?
答案 0 :(得分:0)
我在codeigntor中有一个用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();
?>
File2: libraries / Googleplus.php:
<?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);
}
?>
File4: views / login.php:
<a href="<?php echo $login_url;?>">Login with google</a>