2

POST データを twitch API ( https://api.twitch.com/kraken/oauth2/token ) に送信して json コードを取得するのに苦労しています... これが私の現在のコードです:

$this->config->load("config", true);
$url = "https://api.twitch.tv/kraken/oauth2/token";
$postvars = "client_id=" . $this->config->item('twitch_clientid', 'config') . "&client_secret=" . $this->config->item('twitch_secret', 'config') . "&grant_type=user_read&redirect_uri=" . $this->config->item('twitch_redirect', 'config') . "&code=" . $key;

$temp = curl_init($url);
curl_setopt($temp, CURLOPT_POST, 1);
curl_setopt($temp, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($temp, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($temp, CURLOPT_HEADER, 0);
curl_setopt($temp, CURLOPT_RETURNTRANSFER, 1);
$result = json_decode(@file_get_contents(curl_exec($temp)), true);

しかし...明らかに、それは私がすべき方法ではありません。初めてカールを使用します。
エラー:

A PHP Error was encountered 
Severity: Warning
Message: file_get_contents(): Filename cannot be empty
Filename: controllers/user.php
Line Number: 37

予想される結果:

{
  "access_token": "[user access token]",
  "scope":[array of requested scopes]
}
4

1 に答える 1