簡體   English   中英

向Discord發出php OAuth請求

[英]Making a php OAuth request to 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請求失敗! 第27行的/index.php中的HTTP / 1.1 411長度

strlen是否有可能在陣列上發生故障? 我看到其他人使用類似

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

將數組轉換為可以在查詢中使用的數組。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM