Telegram Bot that retrieve channel subscriptions list

Hi,i’m sorry if my english will be bad :sweat_smile:

I’m requesting help because i’m stacking with a problem : i’m developing a telegram bot that automatically kick user that is not subscribed to a channel,in this moment i use the channel csv subscriber list.

Now, what i want to achieve is : get the list of subscriber from the twitch api, i alredy have the client_secret and client_id of the twitch channel of which I want to get the subscriber list and i have alredy tested the api to obtain the token

GET https://id.twitch.tv/oauth2/authorize
    ?client_id=<your client ID>
    &redirect_uri=<your registered redirect URI>
    &response_type=code
    &scope=<space-separated list of scopes>

but when i use thi endpoint and pass the token i get 401 Unauthorized

curl -X GET 'https://api.twitch.tv/helix/subscriptions?broadcaster_id=141981764' \
-H 'Authorization: Bearer cfabdegwdoklmawdzdo98xt2fo512y' \
-H 'Client-Id: uo6dggojyb8d6soh92zknwmi5ej1q2'

I hope you could help me

That would suggest you didn’t complete step 3 of oAuth and exchange the code for a token.

3) On your server, get an access token by making this request:

POST https://id.twitch.tv/oauth2/token
    ?client_id=<your client ID>
    &client_secret=<your client secret>
    &code=<authorization code received above>
    &grant_type=authorization_code
    &redirect_uri=<your registered redirect URI>
Here is a sample request:

POST https://id.twitch.tv/oauth2/token
    ?client_id=uo6dggojyb8d6soh92zknwmi5ej1q2
    &client_secret=nyo51xcdrerl8z9m56w9w6wg
    &code=394a8bc98028f39660e53025de824134fb46313
    &grant_type=authorization_code
    &redirect_uri=http://localhost
1 Like

tnx for reply me,

how i get the code if i need to login with theese request to obtain it so the channel owner can’t login?

oAuth is as follows

  1. Redirect the User to Twitch
  2. User is redirect to your website with a ?code
  3. Exchange the ?code for a token (and refresh token)

In order to get access to the broadcasters subscription list, you need permission from the broadcaster. So the braodcaster has to login in order to grant that access

ok,so having client_id and client_secret are not enough…ok tnx,

when i get the code,does it expire?

a ?code is one use

A token, has an expire time which is returned when you get it from the API you can also use the validate endpoint to get the current expires_in

Then use the refresh token to get a new access token

tnx you for helping me

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