我正在尝试使用 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很长时间并且它处于活动状态。
有人知道我在这里做错了什么吗?