webapi/acapi/discord.php

40 lines
1.2 KiB
PHP

<?php
include '../vars.php';
global $dctoken;
if ($_GET["token"] != null) {
$dctoken = $_GET["token"];
}
$curl_h = curl_init('https://discord.com/api/users/' . $_GET["id"] . '/profile');
curl_setopt($curl_h, CURLOPT_HTTPHEADER,
array(
'Authorization: ' . $dctoken,
)
);
curl_setopt($curl_h, CURLOPT_RETURNTRANSFER, true);
$json = json_decode(curl_exec($curl_h));
$obj = new stdClass();
if ($json->{'user'} != null) {
$obj->status = 200;
$obj->username = $json->{'user'}->{'username'} . "#" . $json->{'user'}->{'discriminator'};
$obj->accounts = $json->{'connected_accounts'};
if (is_array($json->{'connected_accounts'})) {
foreach ($json->{'connected_accounts'} as $acc) {
if ($acc->{'type'} == "youtube") {
$obj->ytchannel = "https://www.youtube.com/channel/" . $acc->{'id'};
}
elseif ($acc->{'type'} == "twitch") {
$obj->twchannel = "https://www.twitch.tv/". $acc->{'name'};
}
}
}
} else {
$obj->status = 404;
}
echo stripslashes(json_encode($obj));