【问题标题】:Error while processing authentification OAuth2处理身份验证 OAuth2 时出错
【发布时间】:2014-08-07 22:36:46
【问题描述】:

我已按照此tutorial 从 google 获取凭据,但适用于 youtube API 范围,而不是联系 API 之一。

我试过这个:

<?php

session_start();

require 'Google/Client.php';
require 'config.php';

//$_SESSION = array();
$client = new Google_Client();
$client->setApplicationName('Test APPS');
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setScopes($scope);
$client->setRedirectUri($redirectUri);
$client->setAccessType($accessType);

if(isset($_GET['code'])){
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location:' . $redirectUri);
}
if(!isset($_SESSION['token'])){
    $url = $client->createAuthUrl();
?>
<a href="<?php echo $url; ?>">Connect</a>
<?php 
}
?>

点击连接后,我被重定向到谷歌身份验证,并且我有自动范围,但是当在 url 中获取代码时,我得到了错误。

这是错误的回溯

Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unable to connect: 'fopen(https://accounts.google.com/o/oauth2/token) [<a href='function.fopen'>function.fopen</a>]: 
failed to open stream: Invalid argument'' in C:\wamp\www\test\Google\IO\Stream.php:112 Stack trace: #0 C:\wamp\www\test\Google\IO\Abstract.php(125): Google_IO_Stream->executeRequest(Object(Google_Http_Request)) 
#1 C:\wamp\www\test\Google\Auth\OAuth2.php(113): Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) 
#2 C:\wamp\www\test\Google\Client.php(135): Google_Auth_OAuth2->authenticate('4/yNyAID-0XYagI...') 
#3 C:\wamp\www\test\index.php(18): Google_Client->authenticate('4/yNyAID-0XYagI...') 
#4 {main} thrown in C:\wamp\www\test\Google\IO\Stream.php on line 112

知道根本原因吗?

【问题讨论】:

  • 启用了 https 包装器?
  • @Dagon:是的,你是对的!它现在正在工作

标签: php google-api-php-client


【解决方案1】:

我刚刚尝试了var_dump(stream_get_wrappers());,但我没有在数组中找到https。我刚刚取消注释此行 extension=php_openssl.dll 以启用它,现在没问题了。

感谢大衮的评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2017-08-06
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多