skip to Main Content

I try to use this api to get a list of all guilds a user is in, but when i print the response i just see a blank screen.

<?php
session_start();

$url = "https://discord.com/api/users/@me/guilds";
$data = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bearer ' . $_SESSION["access_token"]);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $data);

$response = curl_exec($curl);

curl_close($curl);

$results = json_decode($response);

print_r($results);
?>

2

Answers


  1. Chosen as BEST ANSWER

    Yeah, there is more going on. The access token just works fine. I coded some more and i found the real issue.

    When the api want to visit discord.com i cannot remember it word by word but it said something like "cannot find host discord.com" but then i tried using discordapp.com (the old discord url) and that works fine. Someone that knows how to fix it so i can use discord.com instead?


  2. Check your PHP server’s log. You’re probably trying to read a session key that doesn’t exist.

    Undefined array key "access_token" in test.php on line 5
    

    With your snippet, there’s no way you can ever set the access_token in the $_SESSION, unless there’s more going on.

    Maybe you could use $_COOKIE instead and set the value in browser’s developer console, but it’s not exactly the safest approach, but it will do the trick for your experiments though. Just don’t forget the wipe the cookies after, or give it a short expiration time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search