-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajaxCall.php
executable file
·30 lines (28 loc) · 1.04 KB
/
ajaxCall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Client-ID: nmhtpm541g3et40o6bq8ks8zvaukl5'
));
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html='';
$url = 'https://api.twitch.tv/kraken/channels/'.$_POST['streamer_name'].'/videos';
$json_array = json_decode(file_get_contents_curl($url), true);
if(!empty($json_array) && !isset($json_array['status'])){
foreach($json_array['videos'] as $key => $val){
$html.='<div class="col-md-4" style="margin-bottom:5px;"><div class="media1">';
$html.='<iframe src="https://player.twitch.tv/?channel='.$val['channel']['name'].'" frameborder="0" allowfullscreen="true" scrolling="no" height="250" width="330"></iframe></div></div>';
}
}else{
$html.="Invalid Streamer Name / No Record Found";
}
echo $html;die;
?>