# \[PHP\] Twitch token, return null

**URL:** <https://discuss.dev.twitch.com/t/php-twitch-token-return-null/1930>\
**Category:** API\
**Created:** [March 28, 2015, 7:51pm UTC](https://discuss.dev.twitch.com/t/php-twitch-token-return-null/1930 "2015-03-28T19:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Christensen](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@Eric\_Christensen](https://discuss.dev.twitch.com/u/Eric_Christensen)\
**Post date:** [March 28, 2015, 7:51pm UTC](https://discuss.dev.twitch.com/t/php-twitch-token-return-null/1930/1 "2015-03-28T19:51:13Z")

</div>

```
 if(isset($_GET['code']))
{

    $ch = curl_init('https://api.twitch.tv/kraken/oauth2/token');

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);

    $fields = array(
        'client_id' => 'client_id',
        'client_secret' => 'client_secret',
        'grant_type' => 'authorization_code',
        'redirect_uri' => 'http://localhost/twitch',
        'code' => $_GET['code']
    );

    $fields = http_build_query($fields);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    $data = curl_exec($ch);
    $response = json_decode($data, true);

    var_dump($response);

}

```

With this code i get the return from curl “NULL”, i have read all i can about this in the twitch documentation but i can’t find where im wrong in the code. Anyone got any solution?

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [April 27, 2015, 7:51pm UTC](https://discuss.dev.twitch.com/t/php-twitch-token-return-null/1930/2 "2015-04-27T19:51:26Z")

</div>

Closed on April 27, 2015, 7:51pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
