public void Connect() { try { var tokenPath = $"{GAPIBaseObject.AppDataDir}token.json"; if (File.Exists(tokenPath)) { AccessToken = GAPIBaseObject.LoadFromFile <GAPIAccessToken>("token.json"); if (string.IsNullOrEmpty(AccessToken.refresh_token)) { Logger.Info("Empty refresh token"); Authenticate(); } else { if (AccessToken.expires_at < DateTime.Now) { Logger.Info($"Access token expired at [{AccessToken.expires_at.ToString()}]"); RefreshAccessToken(); } } } else { Logger.Info("Access token does not exist"); Authenticate(); } Logger.Debug($"Access token will expire at [{AccessToken.expires_at.ToString()}]"); } catch (Exception ex) { Logger.Error(ex); throw; } }
public static T SendRequest <T>(string url, GAPIBaseObject obj, GAPIAccountConnection conn) { return(SendRequest <T>(url, JsonConvert.SerializeObject(obj), "POST", conn, "application/json")); }