# Can't create Access Token with code

**URL:** <https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344>\
**Category:** API\
**Created:** [December 18, 2017, 12:53am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344 "2017-12-18T00:53:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 12:53am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/1 "2017-12-18T00:53:29Z")

</div>

Hi

I try to get an **authorization\_code** with [https://api.twitch.tv/kraken/oauth2/token](https://api.twitch.tv/kraken/oauth2/token) with correct params but it return JSON code with status 404, it is normal ? I have try with /helix and /api but issue is same…

People know a solution with my issue ?

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [December 18, 2017, 6:05am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/2 "2017-12-18T06:05:25Z")

</div>

Are you doing a POST request as documented in step 3 of [https://dev.twitch.tv/docs/authentication#oauth-authorization-code-flow-user-access-tokens](https://dev.twitch.tv/docs/authentication#oauth-authorization-code-flow-user-access-tokens)?

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 6:45am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/3 "2017-12-18T06:45:28Z")

</div>

Yes, i have already make the same request before but now i have always 404 response code…

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 6:49am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/4 "2017-12-18T06:49:15Z")

</div>

I try with some system but currently the result is same, 404 response code 😕

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 7:59am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/5 "2017-12-18T07:59:41Z")

</div>

Any people can confirm i can get access\_token with curl in php ? 🤔

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [December 18, 2017, 8:15am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/6 "2017-12-18T08:15:01Z")

</div>

```php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/kraken/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'client_id' => $CLID,
    'client_secret' => $SECRET,
    'grant_type' => 'authorization_code',
    'redirect_uri' => $REDIRECT_URI,
    'code' => $_GET['code']
]));
$output = curl_exec($ch);
curl_close($ch);

$oauth = json_decode($output, true);
// $oauth['access_token'] is user's oauth token

```

is what works for me

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 8:18am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/7 "2017-12-18T08:18:37Z")

</div>

It’s curious i have no value in oauth 🤔 I don’t understand what is your php version ?

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [December 18, 2017, 8:19am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/8 "2017-12-18T08:19:38Z")

</div>

7.0

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 8:49am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/9 "2017-12-18T08:49:46Z")

</div>

Curious i’m with php 7.0.26 I have no result… Do you have an alternative code with php ?

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 8:54am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/10 "2017-12-18T08:54:28Z")

</div>

On execution, the value $oauth = null if i print or var\_dump it

---

<div class="post-metadata">

**Author:** ![mrq-quentin](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/mrq-quentin/32/16960_2.png) [@mrq-quentin](https://discuss.dev.twitch.com/u/mrq-quentin)\
**Post date:** [December 18, 2017, 8:57am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/11 "2017-12-18T08:57:27Z")

</div>

Solution find ! Thank you for your help 😃 I’m just too tired I think xP I have forget to define the right redirect\_uri x)

---

<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 17, 2018, 8:57am UTC](https://discuss.dev.twitch.com/t/cant-create-access-token-with-code/13344/12 "2018-01-17T08:57:32Z")

</div>

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