/// <summary> /// 取得特定日期加Line官方帳號為好友的數量 /// </summary> /// <param name="date">日期(yyyyMMdd)</param> /// <returns>NumberOfFollowersResponseModel</returns> public async Task <NumberOfFollowersResponseModel> GetNumberOfFollowersAsync(string date) { NumberOfFollowersResponseModel responseModel = new NumberOfFollowersResponseModel(); string para = $"/followers?date={date}"; string apiResult = null; apiResult = await Utility.DoLineHttpGetAsync(MessagingApiUrl.InsightUrl, para, accessToken); responseModel = JsonConvert.DeserializeObject <NumberOfFollowersResponseModel>(apiResult); return(responseModel); }
/// <summary> /// 收到 "統計好友數" 後會回覆的文字 /// </summary> /// <param name="receiveText">接收到的訊息</param> /// <returns></returns> private async Task <string> GetNumberOfFollowersTips(string receiveText) { string result = ""; NumberOfFollowersResponseModel responseModel = new NumberOfFollowersResponseModel(); int position = receiveText.IndexOf("."); string date = null; if (position != -1) { date = receiveText.Substring(position + 1); } else { date = DateTime.Now.ToString("yyyyMMdd"); result = @"輸入的格式有誤。 請輸入「好友數.yyyyMMdd」 例如:好友數.20200101"; return(result); } responseModel = await _lineClient.GetNumberOfFollowersAsync(date); switch (responseModel.status) { case NumberOfFollowersStatus.ready: result = $@"{date} 好友統計資料: 加入好友:{responseModel.followers} 目標好友:{responseModel.targetedReaches} 封鎖:{responseModel.blocks}"; break; case NumberOfFollowersStatus.unready: result = "該日的資料尚未統計完成"; break; case NumberOfFollowersStatus.out_of_service: result = "日期格式有誤"; break; default: result = "發生異常,暫時無法查詢"; break; } return(result); }