static void Main(string[] args) { var Token = TokenApi.GetAccessToken("wx98a0e4afc412cd23", "afd66cf094de6ec67ba3406d32c16b88"); Console.WriteLine(Token.access_token); Console.WriteLine("2332"); }
/// <summary> /// Gets an access token from a refresh token /// </summary> /// <param name="refreshToken">The refresh token</param> /// <returns>An access token and its expiration date</returns> private async Task <(string accessToken, DateTime expiration)> RefreshAccessToken(string refreshToken) { string clientId = Properties.Settings.Default.ClientId; string clientSecret = Properties.Settings.Default.ClientSecret.DecryptString(); TokenApi tokenApi = new TokenApi() { AuthorizationHeader = new AuthorizationHeader(clientId, clientSecret) }; dynamic json = await tokenApi.GetAccessToken( refreshToken, errorCallback : (errorResponse) => { MessageBox.Show( errorResponse, "Login failure", MessageBoxButtons.OK, MessageBoxIcon.Error); }); int expiresInSeconds = json.expires_in; DateTime expiration = DateTime.UtcNow.AddSeconds(expiresInSeconds); return(json.access_token, expiration); }