2013-03-13 42 views
2

我試圖與谷歌OAuth2以交換的access_token authorization_code谷歌的OAuth 2身份驗證 - 錯誤:redirect_uri_mismatch甚至註冊URI

$client_id = urlencode(GOOGLE_CLIENT_ID); 
$client_sec = GOOGLE_CLIENT_SECRET; 
$redirect_uri = urlencode("http://example.com/path/auth.php"); 
$code = 'Authorization_code_received'; 
$post="code=$code&client_id=$client_id&client_secret=$client_sec&redirect_uri=$redirect_uri&grant_type=authorization_code"; 
$ch=curl_init(); 
$url="https://accounts.google.com/o/oauth2/token"; 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); 
curl_setopt($ch,CURLOPT_AUTOREFERER,1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch,CURLOPT_POST,1); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$post); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
$json=curl_exec($ch); 
curl_close($ch); 
print_r($json); 

我得到這個 "error" : "redirect_uri_mismatch" 我的問題是完全相同here但我也註冊後我的redirecturi在谷歌api控制檯很長時間和它的活躍。

任何人都知道我在做什麼錯在這裏?

回答

0

https://code.google.com/apis/console併爲您在Client ID for web applications部分重定向的URI ....檢查重定向URI在代碼中設置$redirect_uri = urlencode("http://example.com/path/auth.php");是一樣的谷歌API控制檯....

可能這就是原因上.. 。

+0

我檢查了它們都匹配,仍然有這個問題。儘管感謝您的幫助。 – user1742821 2013-03-20 17:42:40