Php Google OAuth 2 auth-错误:即使在注册uri之后重定向\u uri\u不匹配

Php Google OAuth 2 auth-错误:即使在注册uri之后重定向\u uri\u不匹配,php,curl,google-api,access-token,google-oauth,Php,Curl,Google Api,Access Token,Google Oauth,我正试图用Google OAuth2交换访问令牌的授权码 $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

我正试图用Google OAuth2交换访问令牌的授权码

$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);
我明白了
“错误”:“重定向uri不匹配”
我的问题是完全相同的,但我也注册了我的重定向URI在谷歌api控制台很长一段时间和它的活动


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

转到
https://code.google.com/apis/console
并在
web应用程序的客户端ID中检查重定向URI
部分…检查代码
$redirect\u URI=urlencode(“http://example.com/path/auth.php");与google api控制台上的相同


也许这就是原因…

我检查了一下,它们都匹配,但仍然存在这个问题。谢谢你的帮助。