2013-04-30 122 views
0

UPDATE 如果我执行curl_error()这个获取返回 HTTPS协议不受支持或libcurl中卷曲PHP无法从谷歌获得访问令牌。卷曲返回任何

禁用,如果我发送通过命令行的卷曲请求我得到一个访问令牌罚款:

卷曲--data “代码=删除&的client_id =删除& client_secret =删除& REDIRECT_URI = https://group.cs.cf.ac.uk/group3/oAuth2redirect.php&scope=https://www.googleapis.com/auth/calendar&grant_type=authorization_codehttps://accounts.google.com/o/oauth2/token

然而,当我试图通过PHP卷曲这样做只是没有返回

$code = $_GET['code']; 
$client_id = "removed"; 
$client_secret = "removed"; 
$redirectUri = "https://group.cs.cf.ac.uk/group3/oAuth2redirect.php"; 
$scope = "https://www.googleapis.com/auth/calendar"; 
$grant_type = "authorization_code"; 
$url = "https://accounts.google.com/o/oauth2/token/"; 

$params = array(
      'code' => $code, 
      'client_id' => $client_id, 
      'client_secret' => $client_secret, 
      'redirect_uri' => $redirectUri, 
      'scope' => $scope, 
      'grant_type' => $grant_type 
     ); 


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 
$response = curl_exec($ch); 
curl_close($ch); 

print_r($response); 

有没有人知道为什么这是happerning,我认为这可能与标题,但我真的不能这样做。

任何帮助将使用谷歌的库的oauth2是真棒

编辑 是不是一种选择

回答

2

我现在已经解决了这个问题。原来卷曲未设置为能够做SSL请求(如明显的,因为curl_error()返航HTTPS协议不受支持或libcurl中禁用。

2

我认为SSL创建问题。谷歌为https,因此它需要set_opt(“CURLOPT_SSL_VERIFYPEER”,val)的同时,更多详情,请访问,http://www.php.net/manual/en/function.curl-setopt-array.php旁边其他的东西,这可能是问题。

+0

我已经尝试这个(我删除的选项时,没工作),但它仍然没有返回 – zidsal 2013-04-30 17:37:42

+0

我刚刚做了curl_error()的代码,我已经回到HTTPS协议不受支持或libcurlbool禁用(false – zidsal 2013-04-30 17:41:24