4

我正在尝试使用 Google OAuth2 交换 access_token 的授权码

$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" 完全一样,但我也在google api控制台中注册了我的redirecturi很长时间并且它处于活动状态。

有人知道我在这里做错了什么吗?

4

1 回答 1

0

转到https://code.google.com/apis/console并检查Client ID for web applications部分中的重定向 URI....检查您的代码$redirect_uri = urlencode("http://example.com/path/auth.php");中设置的重定向 URI 是否与 google api 控制台上的相同....

可能是这个原因……

于 2013-03-18T07:41:55.457 回答