Twitch stream on my website constantly gone

$account_is_logged_in =  (bool) db_query_range
(
  'SELECT 1 FROM {sessions} WHERE uid = :uid AND timestamp > :timestamp',
  0,
  1,
  array
  (
    ':uid' => $row->uid,
    ':timestamp' => REQUEST_TIME - (60 * 1),
  )
)->fetchField();

$channelsApi = 'https://api.twitch.tv/helix/streams?client_id=*****&user_login=';

$result = db_select('field_data_field_twitch_username', 'r')
    ->fields('r')
   ->condition('entity_id',$row->field_twitch_username)
    ->execute()
    ->fetchAssoc();
 $channelName=$result['field_twitch_username_value'];
 $clientId = '*****';
 $ch = curl_init();
 curl_setopt_array($ch, array(
    CURLOPT_HTTPHEADER => array(
       'Client-ID: ' . $clientId,
       'Authorization: Bearer *****',
    ),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $channelsApi.$channelName
 ));

 $response = curl_exec($ch);
 curl_close($ch);

$result=json_decode($response);
$offline=TRUE;
if($result->data[0]->type=='live'){$offline=FALSE;}
return $offline;

Hello,

Im using this code to display my livestream and people of my clan on my website, but somehow twitch changes smth and i have to recode the code every week or smth…

this code checks whos online on twitch… if he has the twitchstreaemer role on the website and when he does the stream comes automaticly on my homepage.

but somehow twitch changes stuff and i have to figure out what changed and recode the thing wich cost me ages of time to fix (not a pro in coding).

can one of u tell me what i can change so i dont have to recode all the time?.

im using drupal btw.

thanks!

Nothing has changed recently.

Your code doesn’t seem to use an oAuth token, and you seem to be using client_id as a query string param, helix only accepts ClientID and token via header

This change came in quite a while ago, not last week

You’ll probably use an App Access token:

You may also be interested in EventSub as eventSub will tell you where a channel goes live/offline and saves a lookup

thanks for the quick reply, but doesnt this

 CURLOPT_HTTPHEADER => array(
       'Client-ID: ' . $clientId,
       'Authorization: Bearer *****',

say that its in the header?

I saw this which is in error

I didn’t see this section as it was out of view and I didn’t scroll your code. My bad.

This is correct.

So there does not seem anything obviously wrong in your code.

Other than no HTTP code checking or checking if the response was an error or not.

If your token is hard coded it may have expired

Aaahh awesome i got it now, i changed the bearer token via https://twitchapps.com/tokengen/
and the stream is working again, now i have to find out how to generate an token automaticly :), many thanks for the help man, it really helped me out figuring out what was going wrong!, THANKS!

Yeah don’t use other peoples generators

I already linked you the docs

You can and should use an app access token:

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