Url API v3 to v5

Hi, i’m using this on my code:

https://api.twitch.tv/kraken/users?login=XXX&client_id=XXX

But from yesterday this give me this error:

{“error”:“Gone”,“status”:410,“message”:“v3 is a lie but v5 is still alive. See https://dev.twitch.tv/docs”}

How i convert url for API v5?

Please read the migration guide

https://dev.twitch.tv/docs/v5/guides/migration/

This is complete code i used:

<?php

$channels = array('channel1','channel2') ;

$callAPI = implode(",",$channels);

$dataArray = json_decode(@file_get_contents("https://api.twitch.tv/kraken/streams?channel=" . $callAPI . "&amp;client_id=XXX", false, stream_context_create($arrContextOptions)), true);

if(is_array($dataArray)){

foreach($dataArray['streams'] as $mydata){

if($mydata['_id'] != null){

$name = $mydata['channel']['display_name'];

$game = $mydata['channel']['game'];

$url = $mydata['channel']['url'];

?>

<div id="twitch-embed" class="twitch-embed">

<?php echo "<p><h2><a href='".$url."'> ".$name. " sta giocando a " .$game."</a></h2><br></p>" ; ?>

</div>

<script src="https://embed.twitch.tv/embed/v1.js"></script>

<script type="text/javascript" style="padding: 0 10px;">

new Twitch.Embed("twitch-embed", {

width: 854,

height: 399,

channel: "<?php echo "" .$name. ""; ?>"

});

</script>

<?php

}else{

echo "<p>test</p>";

} } }

if($dataArray['streams'] == null or $dataArray['streams'] == "")

{ ?>

<div id="twitch-embed" class="twitch-embed">

<?php

echo "<p><;h2>Message offline.<;/h2></p>";

echo "<p><h2>submessage</h2></p>;";

}

?>

</div>
  1. Move from file_get_contents to curl
  2. Use cURL to set headers
    <?php
    $ch = curl_init('https://api.twitch.tv/kraken/streams?channel=' . $callAPI);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: application/vnd.twitchtv.v5+json',
        'Client-ID: CLIENTID'
    ));

file_get_contents is insecure for HTTP requests and blocked on most hosts

http://www.php.net/manual/en/function.curl-setopt.php

I have changed $ch with $dataArray but not work

// code.. //

$callAPI = implode(",",$channels);
$dataArray = curl_init('https://api.twitch.tv/kraken/streams?channel=' . $callAPI);
curl_setopt($dataArray, CURLOPT_HTTPHEADER, array(
    'Accept: application/vnd.twitchtv.v5+json',
    'Client-ID: XXX'
));
  
if(is_array($dataArray)){
  foreach($dataArray['streams'] as $mydata){

// code //

I didn’t give a complete solution.

You can learn about PHP cURL in the PHP Docs

https://www.php.net/manual/en/function.curl-setopt.php
https://www.php.net/manual/en/function.curl-exec.php

i’ve done but i cant call multiple streamer and online/offline status, where is the problem?

i’ve tryed switch to helix too, but with helix i cant give online status :confused:

Not sure what you mean, what do you mean you can’t call?

Returns stream status and details for streams

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