# Getting User Token only from server

**URL:** <https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309>\
**Category:** API\
**Created:** [February 4, 2021, 4:56pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309 "2021-02-04T16:56:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boris\_Sbizzera](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/boris_sbizzera/32/11380_2.png) [@Boris\_Sbizzera](https://discuss.dev.twitch.com/u/Boris_Sbizzera)\
**Post date:** [February 4, 2021, 4:56pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/1 "2021-02-04T16:56:09Z")

</div>

Hi,  
I want to get my userToken for my channel to access users-only enpoints of the API. How can i do this?  
I’m abble to get an app accessToken but nothing else.  
Thanks

---

<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:** [February 4, 2021, 4:58pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/2 "2021-02-04T16:58:11Z")

</div>

You will need to create a webpage  
That shows a link to Twitch  
Then you click the link  
Accept the request to link your Twitch and ClientID  
Come back to your webpage  
Grab the `?code` from the query string  
Exchange the code for an access + refresh token

And away you go

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

A node/PHP example are on my Github:

> <https://github.com/BarryCarlyon/twitch_misc/tree/main/authentication/user_access_generator>
>
> //github.com/BarryCarlyon/twitch\_misc/tree/main/authentication/user\_access\_generator

---

<div class="post-metadata">

**Author:** ![Boris\_Sbizzera](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/boris_sbizzera/32/11380_2.png) [@Boris\_Sbizzera](https://discuss.dev.twitch.com/u/Boris_Sbizzera)\
**Post date:** [February 4, 2021, 5:33pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/3 "2021-02-04T17:33:20Z")

</div>

Do there is no way to get a user token only from serveur side? I just want to retrieve my sucribers list… for my own channel…  
Once in get this code, how long will it be valid for ?

---

<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:** [February 4, 2021, 5:35pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/4 "2021-02-04T17:35:28Z")

</div>

> [@Boris\_Sbizzera](#):
>
> Do there is no way to get a user token only from serveur side?

Not “pure server” no. You need to authenticate whenever your token+refresh is completely dead.

> [@Boris\_Sbizzera](#):
>
> Once in get this code, how long will it be valid for ?

A Twitch user access token is valid for 4 hours.  
When that token dies you can use a refresh token to generate a new token.  
A refersh token has no expiraration at time of writing (and when you refresh you may get a new refresh token).

So you only need to do the webpage when you have no token/all tokens are dead.  
From then on it’s all server.  
Unless something causes the refresh token to be invalid, then you’ll have to webpage again to get new keys

---

<div class="post-metadata">

**Author:** ![Boris\_Sbizzera](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/boris_sbizzera/32/11380_2.png) [@Boris\_Sbizzera](https://discuss.dev.twitch.com/u/Boris_Sbizzera)\
**Post date:** [February 4, 2021, 7:52pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/5 "2021-02-04T19:52:04Z")

</div>

Thanks for your help!!

---

<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:** [March 6, 2021, 7:52pm UTC](https://discuss.dev.twitch.com/t/getting-user-token-only-from-server/30309/6 "2021-03-06T19:52:11Z")

</div>

Closed on March 6, 2021, 7:52pm UTC

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