Twitch API returning.... nothing?

I’m trying to do a “simple” php-cURL request to the twitch api and it’s not returning anything at all. No errors, just nothing.

Here’s my code, help is much appreciated c:

<?php

// url/followage.php?user=$(touser)&channel=CHANNELNAME

$user;
$channel;
$clientid = "xxxxx";

if (isset($_GET['user'])){
$user = $_GET['user'];
} else {
    echo "Invalid query - user not supplied";
}

if (isset($_GET['channel'])){
    $channel = $_GET['channel'];
} else {
    echo "Invalid query - channel not specified";
}

$url = "https://api.twitch.tv/kraken/users/" . $user . "/follows/channels/" . $channel;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Client-ID: " . $clientid, "Accept: application/vnd.twitchtv.v3+json"));
$data = curl_exec($ch);
curl_close($ch);

echo $data;

?>

Are you sure you’re not getting an error? curl_exec returns false if there is an error. You can then check for errors with curl_error($ch). Is it outputting false when you do echo $data?

Nope, it’s just returning nothing. Screenshot

Can you post a full example of your url that is experiencing the issue? (I can see what it’s supposed to be concatenated as, I want to see the actual data)

Also, be sure to double check that your client-id is correct.

It’s not live on a public server yet, but I can PM you my IP.

I mean, post the url you’re trying to access, so show your values for $user and $channel

Give this a try:

$user;
$channel;
$clientid = “”;

if (isset($_GET[‘user’])) {
$user = $_GET[‘user’];
} else {
echo “Invalid query - user not supplied”;
}

if (isset($_GET[‘channel’])) {
$channel = $_GET[‘channel’];
} else {
echo “Invalid query - channel not specified”;
}
$url = “https://api.twitch.tv/kraken/users/” . $user . “/follows/channels/” . $channel;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Client-ID: " . $clientid, “Accept: application/vnd.twitchtv.v3+json”));
$data = curl_exec($ch);
curl_close($ch);
echo $data;`

Sir Devexer saving the day like always, thanks bro <3 @TournyMasterBot give this man a medal and a cookie (and a session ;))

1 Like

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