Created
May 22, 2013 15:30
-
-
Save Edocsyl/5628503 to your computer and use it in GitHub Desktop.
Revisions
-
Edocsyl created this gist
May 22, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ <?php /** * Twitch.tv get all channel follower with PHP * @author Edocsyl <kaj@edocsyl.ch> * @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)); ?>