2017-03-21 23 views
1

codeigniterフレームワークでgoogleを使用してログインしようとしています。 以前はうまくいきました。同じコードで以下のエラーメッセージが表示されます。 どうすればこの問題を解決できますか?サーバーでホストされた後メッセージ:HTTPエラー:(0)accounts.google.comへの接続に失敗しました。ポート80:接続がタイムアウトしました

localhostが、それは誤り以下

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 

の下に示して、私のカールスクリプトはこれを解決する方法

$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

@DanielStenbergあなたは更新された質問をご覧ください。サーバーにファイルをアップロードしたときに、エラーメッセージが –

+0

"accounts.google.comポート80への接続に失敗しました"に変更されました。それが言うことを正確に意味します。 curlがそのマシンのホスト "accounts.google.com"のTCPポート80に接続できませんでした。ネットワークの設定、ファイアウォールなどのため。 –

+0

@DanielStenbergどのようにサーバーにファイアウォールがあるかどうかを確認できますか?何が私のリクエストをブロックしていますか? –

答えて

0

私はcodeigntorにgmailでログインするコードを持っています。あなたはコードを変更し、次の4 Fileで試してみることができます。私はこのコードがあなたに役立つと確信しています。

ファイル1: 設定/ 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(); 
?> 

ファイル2: ライブラリ/ 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(); 
} 

} 
?> 

FILE3: コントローラ/ 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: vie ws/login.php:

<a href="<?php echo $login_url;?>">Login with google</a> 
関連する問題