hitboxから情報を取得する
基本的にAPIを使用して取得。
RSSは用意されていないっぽい?
エンドポイント
情報取得
2016/6/22修正
<?php $id_hitbox = "test"; $info = get_hitbox_info($id_hitbox); var_dump($info); function get_hitbox_info($id_hitbox){ $url_base = "https://api.hitbox.tv/media/live/"; $hitbox_url = $url_base . $id_hitbox; $json = file_get_contents($hitbox_url); $arr = json_decode($json, true); // var_dump($arr); $is_live = $arr['livestream'][0]["channel"]["media_is_live"];//配信中は1, 配信していない場合は0 $user_name = $arr['livestream'][0]["channel"]["user_name"]; $viewers = $arr['livestream'][0]["media_views"]; $title = $arr['livestream'][0]["media_status"]; $description = $arr['livestream'][0]["media_description"]; $created_at = $arr['livestream'][0]["media_live_since"]; $user_id = $arr['livestream'][0]["channel"]["user_id"]; $channel_name = $arr['livestream'][0]["media_display_name"]; $cuser_name = $arr['livestream'][0]["channel"]["user_name"]; $url = $arr['livestream'][0]["channel"]["channel_link"]; $info["is_live"]=$is_live; $info["viewers"]=$viewers; $info["title"]=$title; $info["description"]=$description; $info["created_at"]=$created_at; $info["id"]=$user_id; $info["channel_name"]=$channel_name; $info["user_name"]=$user_name; $info["url"]=$url; // $info["lastDate"]=$lastStreamedAt; return $info; } *以下は古い情報 *配信中かどうかと視聴者数を取得 >|php| <?php $url_base = "https://api.hitbox.tv/media/status/"; $hitbox_id = "test"; $url = $url_base . $hitbox_id; $json = file_get_contents($url); $contents = json_decode($json, true); $isLive = $contents['media_is_live']; //配信中はtrue $viewers = $contents['media_views']; //視聴者数
視聴者数以外を取得するには下記
<?php $url_base = "https://api.hitbox.tv/user/"; $hitbox_id = "test"; $url = $url_base . $hitbox_id; $json = file_get_contents($url); $contents = json_decode($json, true); $user_name = $contents['user_name']; $user_cover = $contents['user_cover']; $user_status = $contents['user_status'];//よくわからん $user_logo = $contents['user_logo']; $user_logo_small = $contents['user_logo_small']; $user_is_broadcaster = $contents['user_is_broadcaster'];//よくわからん $followers = $contents['followers']; $user_id = $contents['user_id']; $is_live = $contents['is_live'];//配信中はtrue $live_since = $contents['live_since']; $twitter_account = $contents['twitter_account']; $twitter_enabled = $contents['twitter_enabled']; $user_beta_profile = $contents['user_beta_profile'];
認証してトークンを取得
配信者がAPIを使用して配信タイトル等を変更する場合
<?php $url = 'https://api.hitbox.tv/auth/token'; $data = array( 'login' => 'USER_ID', 'pass' => 'PASSWORD', 'app' => 'desktop', ); $options = array('http' => array( 'method' => 'POST', 'content' => http_build_query($data), )); $contents = file_get_contents($url, false, stream_context_create($options));