vv Post Request vv
$code = $_GET['code'];
$headers = [
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
];
$data = <<<DATA
{
"grant_type": "authorization_code",
"code": $code,
"client_secret": $clientsecret,
"client_id": $clientid
}
DATA;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://discord.com/api/oauth2/token');
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_RETURNHEADERS,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
echo curl_exec($ch);
This code is supposed to return the auth code of a oauth2 auth;
{ "access_token": "6qrZcUqja7812RVdnEKjpzOL4CvHBFG", }
It's supposed to return that. Nothing is being returned on my post request.
Currently, I am trying to oauth2 authorize users in my discord server.
This isn't working, when I send the request and try to print it.
Nothing is returned. My secret client code and client ids are correct.
I don't know what the issue is. Can someone please help me with my issue?
I have tried different ways of sending the request
Needless to say, it still doesn't work.
Please someone help me. I am new with PHP and I don't fully understand all of the issues.
My Answer:
'Content-Type: application/x-www-form-urlencoded', 'Authorization: Basic ' . base64_encode(CLIENT_ID . ':' . CLIENT_SECRET), ];_ $data = [ 'client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => REDIRECT_URI, ];_ $ch = curl_init('https://discord.com/api/oauth2/token');_ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));_ $response = curl_exec($ch);_ curl_close($ch);_ var_dump($response);
Rate this post
4 of 5 based on 6613 votesComments