问题很简单。
将oAuth2代码发送到页面时。此php脚本接收令牌json无效。请帮我:c
$base64 = base64_encode($data['id'] . ':' . $data['secret']);
$info = curl_init();
curl_setopt_array($info, array(
CURLOPT_URL => "https://discordapp.com/api/oauth2/token?grant_type=authorization_code&code=" . $data['code'] . "&redirect_uri=" . urlencode($data['redirect']),
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . $base64,
'Content-Length: ' . strlen($base64)
),
CURLOPT_RETURNTRANSFER => true
));
$tinyresult = curl_exec($info);
curl_close($info);
return $tinyresult;
答案 0 :(得分:0)
问题解决了:D
$info = curl_init();
curl_setopt_array($info, array(
CURLOPT_URL => "https://discordapp.com/api/oauth2/token",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
"grant_type" => "authorization_code",
"client_id" => $data['id'],
"client_secret" => $data['secret'],
"redirect_uri" => $data['redirect'],
"code" => $data["code"],
),
CURLOPT_RETURNTRANSFER => true,
));
$tinyresult = curl_exec($info);
if ($tinyresult == false) {
$tinyerror = curl_error($info);
} else {
$tinyerror = null;
$tinyresult = json_decode($tinyresult);
}
$httpcode = curl_getinfo($info, CURLINFO_HTTP_CODE);
curl_close($info);
return array(
"data" => $tinyresult,
"err" => $tinyerror,
"state" => $httpcode,
);