更新如果我执行 curl_error() 这将返回 Protocol https not supported or disabled in libcurl
如果我通过命令行发送 curl 请求,我会得到一个访问令牌:
curl --data "code=removed&client_id=removed&client_secret=removed&redirect_uri= https://group.cs.cf.ac.uk/group3/oAuth2redirect.php&scope=https://www.googleapis.com/auth/calendar&grant_type=authorization_code " https ://accounts.google.com/o/oauth2/token
但是,当我尝试通过 php curl 执行此操作时,什么也不返回
$code = $_GET['code'];
$client_id = "removed";
$client_secret = "removed";
$redirectUri = "https://group.cs.cf.ac.uk/group3/oAuth2redirect.php";
$scope = "https://www.googleapis.com/auth/calendar";
$grant_type = "authorization_code";
$url = "https://accounts.google.com/o/oauth2/token/";
$params = array(
'code' => $code,
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $redirectUri,
'scope' => $scope,
'grant_type' => $grant_type
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
有谁知道为什么会发生这种情况,我认为这可能与标题有关,但我真的无法解决这个问题。
任何帮助都是极好的
不能使用 Google 的 oauth2 库进行编辑