2011-11-23 135 views
0

我想获取我的用户的电子邮件与谷歌API的&卷曲,我坚持兑换访问令牌。我拿到钥匙没有问题,但是当它涉及到的道理,谷歌刚刚返回JSON谷歌访问API与PHP卷曲

{"error" : "invalid_request"} 
下面

是赎回代码为令牌(以及至少它应该)

$code = urlencode($_GET["code"]); 
$secret = "MYSECRET"; 
$client_id = "MYCLIENTID"; 
$redirect_uri = urlencode("http://www.mysupersite.com/callback.html"); 
$grant_type = "authorization_code"; 

$url = "https://accounts.google.com/o/oauth2/token"; 

$headers = array("Content-type: application/x-www-form-urlencoded"); 

$post = "code=".$code."&client_id=".$client_id."&secret=".$secret."&redirect_uri=".$redirect_uri."&grant_type=".$grant_type; 

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); 
curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); 
curl_setopt($curl, CURLOPT_POST, TRUE); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); 
curl_setopt($curl, CURLOPT_VERBOSE, TRUE); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
$json = curl_exec($curl); 
curl_close($curl); 

var_dump($json); 

我的一个片段我真的陷入困境,谷歌API从来没有告诉你究竟是什么错误。

UPD我知道这种类型的调用有一个库,但我正在解决一个简单的任务(很好地根据谷歌api文档),只是看到包括其他方法的负载没有意义。

回答

0

好吧我的坏 - $ _GET [“秘密”]需要$ _GET [“client_secret”]