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;
}