I am trying to get my channel’s subscribers data but twitch api returns raw hex data everytime and i can not parse it
here is the response returned by twitch
1f8b 0800 85e1 695a 0003 14cc 310a 8030
0c40 d1ab 84cc 9d8a 93bb 47f0 0051 432d
d844 9228 8878 7775 fe8f 7f23 9ba9 618f
a3ec a633 bbd3 b431 0c12 352e 4ce8 4171
38f6 5dce 09db 9f0b 7f9a 4559 c22e 5894
1d44 0356 3a19 08fc 987c b6ba 4755 81ef
588c 1a3e 2f00 0000 ffff 0300 6b16 b26a
6700 0000
How are you reading the response?
Im sending a curl request with php and there is no problem with user info or channel info but when i try to get channel subscribers this is the result
this is my request function
public static function request(string $url, string $method = ‘GET’, $payload = null, array $headers = null){
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
));
if(is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if(is_array($payload)) {
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($payload)
));
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
$result = curl_exec($ch);
$parsed = json_decode($result, TRUE);
if(!json_last_error()){
return $parsed;
} else {
file_put_contents('fucked', $result);
}
return $result;
}
and im calling it with this function
public function getChannelSubscribers($id, $token){
$headers = array(
'Accept: application/vnd.twitchtv.v5+json',
'Client-ID: ' . $this->clientId,
'Authorization: OAuth ' . $token,
);
$result = Http::get('https://api.twitch.tv/kraken/channels/' . $id . '/subscriptions', null, $headers);
return $result;
}
Alright i figured it out. API server responses with gzip encoded data sometimes, everything is fine!
1 Like
george
January 25, 2018, 2:27pm
6
When it doubt blame gzip or DNS.
1 Like
system
Closed
February 24, 2018, 2:27pm
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.