谷歌OAuth 2 auth -错误:redirect_uri_mismatch即使在注册的uri


Google OAuth 2 auth - Error: redirect_uri_mismatch even after registered uri

我正在尝试与Google OAuth2交换access_token的authorization_code

$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"我的问题是完全相同的,但我也注册了我的redirecturi在谷歌api控制台很长一段时间,它的活动。

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

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

相同。