# Unauthorized 401 Client ID and OAuth token do not match

**URL:** <https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488>\
**Category:** API\
**Created:** [August 3, 2020, 1:31pm UTC](https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488 "2020-08-03T13:31:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11153](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/11153/32/9860_2.png) [@11153](https://discuss.dev.twitch.com/u/11153)\
**Post date:** [August 3, 2020, 1:31pm UTC](https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488/1 "2020-08-03T13:31:46Z")

</div>

Hello, I wanted to make a live / offline stream for the site.  
to get the token I use the following code

```
 <?php
 $url = 'https://id.twitch.tv/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=client_credentials';
 
 if( $curl = curl_init() ) {
 		curl_setopt($curl, CURLOPT_URL, $url);
 		curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
 		curl_setopt($curl, CURLOPT_POST, true);
 		
		$out = curl_exec($curl);
 		$data= json_decode ($out, true);
 		$access_token = $data['access_token'];
 		echo $access_token;
		 		
		curl_close($curl);
 }

 $ch = curl_init('https://api.twitch.tv/helix/streams?user_login=xxxxxx');

 $options = array(        
    CURLOPT_HEADER => false,
     CURLOPT_HTTPHEADER => array("Client-ID: xxxxxx"),
    CURLOPT_HTTPHEADER => array("Authorization: Bearer xxxxxx"),
);
 curl_setopt_array($ch, $options);
 curl_exec($ch); 
 curl_close($ch);

```

But it doesn’t work  
{“error”: “Unauthorized”, “status”: 401, “message”: “Client ID and OAuth token do not match”}

I tried and just insert token and also do via variable $access\_token.

P.S. Sorry my english

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 3, 2020, 1:32pm UTC](https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488/2 "2020-08-03T13:32:40Z")

</div>

```auto
 $options = array(        
    CURLOPT_HEADER => false,
     CURLOPT_HTTPHEADER => array("Client-ID: xxxxxx"),
    CURLOPT_HTTPHEADER => array("Authorization: Bearer xxxxxx"),
);

```

should be

```auto
 $options = array(        
    CURLOPT_HEADER => false,
     CURLOPT_HTTPHEADER => array(
        "Client-ID: xxxxxx",
        "Authorization: Bearer xxxxxx"
    ),
);

```

---

<div class="post-metadata">

**Author:** ![11153](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/11153/32/9860_2.png) [@11153](https://discuss.dev.twitch.com/u/11153)\
**Post date:** [August 3, 2020, 1:34pm UTC](https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488/3 "2020-08-03T13:34:58Z")

</div>

It works, thanks a lot!

---

<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:** [September 2, 2020, 1:35pm UTC](https://discuss.dev.twitch.com/t/unauthorized-401-client-id-and-oauth-token-do-not-match/27488/4 "2020-09-02T13:35:01Z")

</div>

Closed on September 2, 2020, 1:35pm UTC

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