Skip to content

Instantly share code, notes, and snippets.

@Edocsyl
Created May 22, 2013 15:30
Show Gist options
  • Save Edocsyl/5628503 to your computer and use it in GitHub Desktop.
Save Edocsyl/5628503 to your computer and use it in GitHub Desktop.
Get the Twitch.tv followers with php
<?php
/**
* Twitch.tv get all channel follower with PHP
* @author Edocsyl <[email protected]>
* @date 18.05.13
* @version 1.0
*/
class twitchfollow {
private function createUrl($data = array()){
return'https://api.twitch.tv/kraken/channels/' . $data[0] . '/follows.json?limit=' . $data[1] . '&offset=' . $data[2] . ($data[3] == true ? '&callback=?' : '');
}
private function makeJSONCall($url){
$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);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
public function getFollower($channel, $limit, $offset = 0, $callback = false){
$callback = $this->makeJSONCall($this->createUrl(array($channel, $limit, $offset, $callback)));
$callback = $callback->follows;
$followerarray = array();
foreach($callback as $flow){
$followertmp = $flow->user;
$follower = array(
'name' => $followertmp->name,
'display_name' => $followertmp->display_name,
'logo' => $followertmp->logo,
);
array_push($followerarray, $follower);
}
return $followerarray;
}
}
/**
* Usage
*/
$twitchfollow = new twitchfollow();
var_dump($twitchfollow->getFollower('Edocsyl', 100));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment