Im setting up an credit system that checks if the user followed someone that is also on the website on Twitch. Now i've set up a base, what I think it should do the trick.
The thing now is, it checks everytime by cronjob every 10 minutes, but if i do it manually now, it just gives other responses, like the other time it says he followed the other, but if i refresh then it says he didnt follow him.
You think what's the point you only give out the credits once? Yes, that is true, but if it says that they don't follow we rip some credits from the user that unfollowed the other user on Twitch.
I don't know how to get the solid setup with the same results every refresh for example.
$get_streamer = $mysqli->query("SELECT `streamer`, `streamer_id` FROM `users` WHERE `streamer_id` != ''");
while($streamer = $get_streamer->fetch_object()) {
//Check Affiliate
$url1 = 'https://api.twitch.tv/helix/users?id='.$streamer->streamer_id;
$gettwitch1 = json_decode(file_get_contents_curl($url1), true);
$url2 = 'https://api.twitch.tv/helix/users/follows?from_id='.$gettwitch1['data'][0]['id'];
$gettwitch2 = json_decode(file_get_contents_curl($url2), true);
$get_streamer2 = $mysqli->query("SELECT `streamer`, `streamer_id` FROM `users` WHERE `streamer_id` != '".$streamer->streamer_id."' AND `streamer_id` != ''");
while($streamer2 = $get_streamer2->fetch_object()) {
$ii = 0;
for ($i=0, $len=count($gettwitch2['data']); $i < $len; $i++){
if ($gettwitch2['data'][$i]['to_id'] == $streamer2->streamer_id){
$ii++;
}
}
if ($ii == 0){
echo $streamer->streamer." did not follow ".$streamer2->streamer."!<br />";
} else {
echo $streamer->streamer. " did follow ".$streamer2->streamer."!<br />";
}
}
echo "<br />";
echo "<br />";
}