# Get Access Token

**URL:** <https://discuss.dev.twitch.com/t/get-access-token/1364>\
**Category:** API\
**Created:** [December 26, 2014, 10:07pm UTC](https://discuss.dev.twitch.com/t/get-access-token/1364 "2014-12-26T22:07:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![officialrakma](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@officialrakma](https://discuss.dev.twitch.com/u/officialrakma)\
**Post date:** [December 26, 2014, 10:07pm UTC](https://discuss.dev.twitch.com/t/get-access-token/1364/1 "2014-12-26T22:07:36Z")

</div>

```
echo "<br>Here is your code: " . $code.'<br>'; 

$ch = curl_init($base_url . "oauth2/token");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$fields = array(
     'client_id' => $client_id,
     'client_secret' => $client_secret,
     'grant_type' => 'authorization_code',
     'redirect_uri' => $redirect_uri,
     'code' => $code
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$data = curl_exec($ch);
$response = json_decode($data, true);

echo "<pre>".print_r($response,true)."</pre>";

echo 'Here is your token: '.$response["access_token"];

```

}

ok so im getting the CODE from [twitch.tv](http://twitch.tv) but i cant get the acces token and im running this from a local machine. Some items i get NULL on the token

---

<div class="post-metadata">

**Author:** ![officialrakma](https://avatars.discourse-cdn.com/v4/letter/o/bbce88/32.png) [@officialrakma](https://discuss.dev.twitch.com/u/officialrakma)\
**Post date:** [December 26, 2014, 10:46pm UTC](https://discuss.dev.twitch.com/t/get-access-token/1364/2 "2014-12-26T22:46:15Z")

</div>

Ok so i found out that this dosent work on a LOCAL Machine…

---

<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:** [January 5, 2015, 10:46pm UTC](https://discuss.dev.twitch.com/t/get-access-token/1364/3 "2015-01-05T22:46:32Z")

</div>

Closed on January 5, 2015, 10:46pm UTC

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