Error while processing authentification OAuth2

只愿长相守 提交于 2019-12-11 11:26:31

问题


i have follow this tutorial to get credentials from google but for youtube API scope instead of contact API one.

I have tried with this:

<?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 
}
?>

after clicking on connect i have been redirected to google authentification and i have autorize scope but when getting code in url i got error with it.

this is the traceback of the error

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

any idea of the root cause?


回答1:


I have just tried var_dump(stream_get_wrappers()); and i didnt found https in the array. i have just uncomment this line extension=php_openssl.dll to enable it and now it is ok.

thanks to Dagon's commment.



来源:https://stackoverflow.com/questions/25193378/error-while-processing-authentification-oauth2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!