using log4net; using OT.COM.ArsenalDB; using System; using System.Collections.Concurrent; namespace CounsellorBL.Helper { public class APIURLHelper { private ILog Logger { get; } = LogManager.GetLogger(typeof(APIURLHelper)); private string ApiVersion { get; set; } public APIURLHelper() { const string error_information = "API version initial failed"; try { ConcurrentDictionary dicSetting = CustomizeDBMgr.SettingData; ApiVersion = dicSetting.ContainsKey("FB_API_VERSION") ? dicSetting["FB_API_VERSION"] : "v7.0"; if (string.IsNullOrWhiteSpace(ApiVersion)) throw new Exception(error_information); } catch(Exception ex) { Logger.Error($"{error_information}, Excepiton: {ex.ToString()}"); throw ex; } } public string SendMessage(string access_token_) => $"https://graph.facebook.com/{ApiVersion}/me/messages?access_token={access_token_}"; public string CheckAccessToken(string access_token_) => $"https://graph.facebook.com/{ApiVersion}/debug_token?input_token={access_token_}&access_token={access_token_}"; public string GetUserAccessToken(string user_access_token_, string app_id_, string app_secret) => $"https://graph.facebook.com/{ApiVersion}/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id_}&client_secret={app_secret}&fb_exchange_token={user_access_token_}"; public string GetPageAccessToken(string user_id_, string long_lived_user_access_token) => $"https://graph.facebook.com/{ApiVersion}/{user_id_}/accounts?access_token={long_lived_user_access_token}"; public string GetGroupPublicDescription(string group_id_, string user_access_token_) => $"https://graph.facebook.com/{ApiVersion}/{group_id_}?access_token={user_access_token_}"; } }