/// <summary> /// ライブIDからアカウント名を取得する /// </summary> /// <param name="liveId"></param> /// <returns></returns> public string GetAccountNameFromLiveId(ulong liveId) { string accountName = ""; string lastUpdatedAt = MyUtil.GetUnixTime(DateTime.Now).ToString() + "000"; string apiUrl = " https://api.whowatch.tv/lives/" + liveId + "?last_updated_at=" + lastUpdatedAt; string recvStr = doHttpRequest(apiUrl); try { // JSON形式からふわっちAPIオブジェクトに変換 WhoWatchApiObject whoWatchApiObj = JsonConvert.DeserializeObject <WhoWatchApiObject>(recvStr); if (whoWatchApiObj.live != null && whoWatchApiObj.live.user != null) { // アカウント名(Note:ふわっちAPIではuser_pathにあたる. account_nameは別物) accountName = whoWatchApiObj.live.user.user_path; } } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message + " " + exception.StackTrace); } return(accountName); }
/// <summary> /// ふわっちコメント取得処理 /// </summary> private void whoWatchGetComments() { if (this.LiveId == 0) { //System.Diagnostics.Debug.WriteLine("[ERROR]whoWatchGetCommentsHandle liveId = 0"); return; } string apiUrl = " https://api.whowatch.tv/lives/" + this.LiveId + "?last_updated_at=" + lastUpdatedAt; string recvStr = doHttpRequest(apiUrl); try { // JSON形式からふわっちAPIオブジェクトに変換 WhoWatchApiObject whoWatchApiObj = JsonConvert.DeserializeObject <WhoWatchApiObject>(recvStr); // JSONオブジェクトからコメント一覧を取得 IList <CommentStruct> workCommentList = parseCommentsFromWhoWatchApiObj(whoWatchApiObj); foreach (CommentStruct tagtComment in workCommentList) { OnCommentReceiveEach(this, tagtComment); } OnCommentReceiveDone(this); // 更新日時の更新 lastUpdatedAt = whoWatchApiObj.updated_at; System.Diagnostics.Debug.WriteLine("lastUpdatedAt " + lastUpdatedAt); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message + " " + exception.StackTrace); } }
/// <summary> /// ふわっちAPIオブジェクトを解析してコメントリストを取得する /// </summary> /// <param name="whoWatchApiObj"></param> /// <returns></returns> IList <CommentStruct> parseCommentsFromWhoWatchApiObj(WhoWatchApiObject whoWatchApiObj) { IList <CommentStruct> workCommentList = new List <CommentStruct>(); foreach (Comment comment in whoWatchApiObj.comments) { CommentStruct workComment = new CommentStruct(); workComment.Id = comment.id; workComment.UserThumbUrl = comment.user.icon_url; workComment.UserName = comment.user.name; workComment.TimeStr = comment.posted_at; workComment.Text = comment.message; workComment.IsBouyomiOn = true; // 初期値 //System.Diagnostics.Debug.WriteLine("Id " + workComment.Id); //System.Diagnostics.Debug.WriteLine("UserThumbUrl " + workComment.UserThumbUrl); //System.Diagnostics.Debug.WriteLine("UserName " + workComment.UserName); //System.Diagnostics.Debug.WriteLine("TimeStr " + workComment.TimeStr); //System.Diagnostics.Debug.WriteLine("Text " + workComment.Text); workCommentList.Add(workComment); } return(workCommentList); }