2011-11-23 173 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」]