Update content on the basis of response returned from api

I need a unique field from twitch api which can be saved in as id in the database and used in the future to update and remove the content.

I am getting this array from the api.
[streams] => Array
[0] => stdClass Object
[_id] => 18020765264
[game] => Dota 2
[viewers] => 5731
[created_at] => 2015-12-03T09:02:27Z
[video_height] => 720
[average_fps] => 60.5095541401
[delay] => 120
[is_playlist] =>
[_links] => stdClass Object
[self] => https://api.twitch.tv/kraken/streams/dotapit
) [preview] => stdClass Object
[small] => http://static-cdn.jtvnw.net/previews-ttv/live_user_dotapit-80x45.jpg
[medium] => http://static-cdn.jtvnw.net/previews-ttv/live_user_dotapit-320x180.jpg
[large] => http://static-cdn.jtvnw.net/previews-ttv/live_user_dotapit-640x360.jpg
[template] => http://static-cdn.jtvnw.net/previews-ttv/live_user_dotapit-{width}x{height}.jpg
) [channel] => stdClass Object
[mature] =>
[status] => LIVE: Mineski vs Fnatic - DOTA PIT SEA by G2A w/ @TobiWanDOTA @MotPax
[broadcaster_language] => en
[display_name] => dotapit
[game] => Dota 2
[language] => en
[_id] => 59168409
[name] => dotapit
[created_at] => 2014-03-18T16:16:57Z
[updated_at] => 2015-12-03T12:16:35Z
[delay] =>
[logo] => http://static-cdn.jtvnw.net/jtv_user_pictures/dotapit-profile_image-00bf5ddfd68cec9b-300x300.jpeg
[banner] =>
[video_banner] =>
[background] =>
[profile_banner] =>
[profile_banner_background_color] =>
[partner] => 1
[url] => http://www.twitch.tv/dotapit
[views] => 8686970
[followers] => 47825
[_links] => stdClass Object
[self] => http://api.twitch.tv/kraken/channels/dotapit
[follows] => http://api.twitch.tv/kraken/channels/dotapit/follows
[commercial] => http://api.twitch.tv/kraken/channels/dotapit/commercial
[stream_key] => http://api.twitch.tv/kraken/channels/dotapit/stream_key
[chat] => http://api.twitch.tv/kraken/chat/dotapit
[features] => http://api.twitch.tv/kraken/channels/dotapit/features
[subscriptions] => http://api.twitch.tv/kraken/channels/dotapit/subscriptions
[editors] => http://api.twitch.tv/kraken/channels/dotapit/editors
[teams] => http://api.twitch.tv/kraken/channels/dotapit/teams
[videos] => http://api.twitch.tv/kraken/channels/dotapit/videos
) ) ) )

Like _id?

1 Like

Actually I am not quite sure about it. If any one used it as unique and haven’t faced any problem. Then I will prefer to use it. Because I didn’t find any documentation of it to be unique.

_id is a unique identifier that’s tied to the object.

Actually, what’s confusing me about this is.
When a channel is online then it is attached to a particular id. But when it goes offline the streams becomes null.

I am not quite sure about as I didn’t get the time to observe it : when it again comes online it uses the same _id as it was before?

The stream _id is different from the channel _id. When the stream isn’t live, there is no stream so the stream is null. If that’s the case, you may want to request /channels/:channel instead to get the channel object, which is a part of the streams response when the channel is live.

1 Like

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