redirect_url 交换令牌代码时出现不匹配错误

redirect_url mismatch error when exchanging code for token

我正在尝试在我的 WebApi 应用程序中使用 Fitbit 交换令牌代码。我一直收到异常,Message = "Redirect_uri mismatch: http://localhost:49294/api/... Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."

RequestUserAuthorizationUrl

string authorizationLink;
try
{
    string[] scopes = {"profile", "activity", "heartrate", "weight", "location", "sleep", "nutrition"};
    authorizationLink = Authenticator().GenerateAuthUrl(scopes);
}
catch (Exception e)
{
    AppUtils.LogException(" FitbitHandler/RequestUserAuthorizationUrl ", e);
    authorizationLink = string.Empty;
}
return authorizationLink;

获取用户令牌

public async Task<OAuth2AccessToken> GetUserToken(string code)
{
    if (_requestToken != null)
        return _requestToken;

    _requestToken = await Authenticator().ExchangeAuthCodeForAccessTokenAsync(code);
    return _requestToken;
}

验证者

private OAuth2Helper Authenticator()
{
    var appCredentials = new FitbitAppCredentials
    {
       ClientId = _consumerKey,
       ClientSecret = _consumerSecret
    };
   return new OAuth2Helper(appCredentials, CallbackUrl);
}

您的重定向 url 应该与您在应用设置中提供的内容相匹配。