我正在尝试与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控制台....