title: PHP - Send post data to URL and get the response
body: <p>I'm having a hard time trying to send POST data to the twitch api (<a href="https://api.twitch.com/kraken/oauth2/token" rel="nofollow">https://api.twitch.com/kraken/oauth2/token</a>) and get back the json code... This is my current code:</p>
  
  <pre><code>$this-&gt;config-&gt;load("config", true);
  $url = "https://api.twitch.tv/kraken/oauth2/token";
  $postvars = "client_id=" . $this-&gt;config-&gt;item('twitch_clientid', 'config') . "&amp;client_secret=" . $this-&gt;config-&gt;item('twitch_secret', 'config') . "&amp;grant_type=user_read&amp;redirect_uri=" . $this-&gt;config-&gt;item('twitch_redirect', 'config') . "&amp;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);
  </code></pre>
  
  <p>But... obviously that is not the way I should be doing it. First time working with curl.
  <br />
  Error:</p>
  
  <pre><code>A PHP Error was encountered 
  Severity: Warning
  Message: file_get_contents(): Filename cannot be empty
  Filename: controllers/user.php
  Line Number: 37
  </code></pre>
  
  <p>Result expected:</p>
  
  <pre><code>{
    "access_token": "[user access token]",
    "scope":[array of requested scopes]
  }
  </code></pre>