Exchange Token not working?
If I try to refresh the token to work for another +1h it only returns an empty string.
To refresh I'm saving the "payload.code" on AuthorizationCodeAuth to a string variable called "RefreshToken" which I'm using in my regentoken method.
this is the code I used there:
if (token.IsExpired())
{
// Regen Token
token = await auth.ExchangeCode(RefreshToken);
_spotifyweb = new SpotifyWebAPI()
{
TokenType = token.TokenType,
AccessToken = token.AccessToken
};
}
Code where I'm getting the RefreshToken from (based on example app)
private async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
{
auth = (AuthorizationCodeAuth)sender;
auth.Stop();
token = await auth.ExchangeCode(payload.Code);
RefreshToken = payload.Code;
_spotifyweb = new SpotifyWebAPI()
{
TokenType = token.TokenType,
AccessToken = token.AccessToken
};
GetProfile(_spotifyweb);
}
I guess I'm missing something since the latest (3.0.2) NuGet Update and I can't see whats missing so I would appreciate some hints ^^'
RefreshToken = payload.Code; => RefreshToken = payload.RefreshToken;
I think the problem is RefreshToken = payload.Code; because the refresh token should be stored in the Token object you get from RefreshToken = payload.Code;.
Also I think token = await auth.ExchangeCode(RefreshToken); shouldn't work but I wasn't able to find the right method yet.
Gnarf ... tripple facepalm. ^^' ... Thanks for the fast answers you two ❤️
/edit
payload does not have RefreshToken :3

Oh sorry, my bad, it's token.RefreshToken
Ah ok ... I'll try that and respond in an hour if it worked or not ^^'
Token is still empty after refresh. :(
Ausnahme ausgelöst: "System.NullReferenceException"
After 1 hour it stops working. :/ .NET Framework 4.6.2
Oh I think @h-philip made a valid point, exchangecode is for the initial token, seems like I forgot to Port refreshToken 😐
Will update tomorrow
Oh well then it makes sense ^^' thought it's the new way so I changed it on code :3 ... thanks for fixing in advance 👍 :)
Fixed in 70a57579cf19d573fb7fbf041b99e20ee52c33f1
Simply use Token refreshedToken = auth.RefreshToken(token.RefreshToken)