У меня есть этот код, и я хочу, чтобы токен аутентификации отображался на экране. Однако отображаются только «start gettoken
» и «test after curl
». И токен отсутствует. Что не так в коде? Запрос curl выполняется вообще?
function getToken1() {
echo "start gettoken";
$jsonStr = http_build_query(Array(
"client_id" => "**",
"scope" => "https://graph.microsoft.com/.default",
"client_secret" => "**",
"grant_type" => "client_credentials"
));
$headers = Array("Content-Type: application/x-www-form-urlencoded");
$ch = curl_init("https://login.microsoftonline.com/**.onmicrosoft.com/oauth2/v2.0/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$token = curl_exec($ch);
echo "test after curl";
echo $token;
return $token;
}