Создание php OAuth-запроса на Discord

Некоторое время боролся. Пытаюсь получить мой токен от раздора.

Пожалуйста, дайте мне знать, где я иду не так.

<?php
ini_set('display_errors',1);

$code = '';
$code = $_GET['code'];

if(isset($code)){

$postData = array(
'code' => $code,
'client_id' => "[omitted]",
'client_secret' => '[omitted]',
'redirect_uri' => '[omitted]'
);

// Create the context for the request
$context = stream_context_create(array(
'http' => array(
// http://www.php.net/manual/en/context.http.php
'method' => 'POST',
'content' => $postData,
'header' => "Authorization: Bot [omitted]\r\n".
"Content-Length: ".strlen($postData)."\r\n",
)
));

// Send the request
$response = file_get_contents('https://discordapp.com/api/oauth2/authorize', FALSE, $context);

echo $response;

} else {
echo '<a href="https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=[omitted]&scope=identify%20guilds&client_id=[omitted]">Login</a>';
}

Я получаю ошибку

Предупреждение: file_get_contents (https://discordapp.com/api/oauth2/authorize): не удалось открыть поток: ошибка HTTP-запроса! HTTP / 1.1 Длина 411 Требуется в /index.php в строке 27

0

Решение

Возможно ли, что strlen терпит неудачу на массиве? Я видел, как другие люди используют что-то вроде

$postData = http_build_query(array('foo'=>'bar'))

превратить массив в то, что они могут использовать в запросе.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector