首页 文章

向Discord发出php OAuth请求

提问于
浏览
0

一直苦苦挣扎 . 试图从不和谐中获取我的令牌 .

请让我知道我哪里出错了 .

<?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请求失败!第27行/index.php中需要HTTP / 1.1 411长度

1 回答

  • 0

    strlen是否有可能在阵列上失败?我见过其他人用过类似的东西

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

    将数组转换为可在查询中使用的内容 .

相关问题