How to save username or channel id of our website user in our database to stream their channel on twitch

I want to develop an application where registered user of my application can stream their gaming sessions on twitch. I’m able to live my gaming sessions video using:
https://player.twitch.tv/?channel=myChannel

but i want to know from where i will get username or channel name of my registered user so that i can pass it to api to view live streaming.

Assuming you have used an oAuth loop to log the user into your website, then you have an access token for that user.

Call the users API

with just the token and there you go

Thanks, Can you please provide a link for oAuth login, i’m using PHP as a programming language.

The usual oAuth flow is covered here:

One redirect
One cURL request after the user comes back to your website.

So i will save that user_id for future use in my database,Is compulsory for user to login to twitch (in my application) before starting streaming, i was using OBS, or there is any better alternative

If they don’t login and/or register you have no information about them, so how are you supposed to get their user ID without registration and/or login with Twitch?

It will only require one time registration and login using twitch, right?

You can do whatever kind of login to your system that you want. And then add a “link your Twitch account” button in your profile system, or just use login to Twitch to start.

saving “id”: “44322889”,“login”: “dallas” is sufficient in local database or i need to save all the fields.

I don’t know.

It’s your application, you should decide what you want to keep/cache

Can you please provide the link to logout after i have run following code to extract user info:
$curl = curl_init(‘https://api.twitch.tv/kraken/user’);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Disables SSL verification
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
‘Accept: application/vnd.twitchtv.v5+json’,
'Client-ID: ’ . $client_id,
'Authorization: OAuth ’ . $result[‘access_token’]
));
$user = curl_exec($curl);

Logout of what?

Your website? That depends on your session manager that you have for your website

The API doesn’t have a “logout” method since you never logged in.

The API has a “revoke” access key method, but generally you don’t need to use that, since you probably want to store the users access and refresh tokens in order to continue to use their access keys

I’m still login in Twitch after i am authenticated through OAuth, is there is any way to logout from twitch or logout should be manual. When i run https://www.twitch.tv/myprofile i see that i’m login.

You cannot use the API to logout of the main Twitch website.

If you’re using the symfony framework, you can always use the oauth bundle. It can be a pain to configure but it handles most of this for you.

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