Function TSpManager.GetRefreshToken(Quiet: Boolean):Boolean;
var s,Encoded:
string;
Client: TRestClient;
Request: TRESTRequest;
Response: TRestResponse;
MValue:TJSONValue;
begin
result:= false;
Client := TRestClient.Create('
https://accounts.spotify.com/api/token');
Response := TREStResponse.Create(
NIL);
Request := TRESTRequest.Create(
NIL);
try
s := stcf.AccessData.clientID + '
:' + stcf.AccessData.clientsecret;
Encoded:= replacestr(TNetEncoding.Base64.Encode(s),#13#10,'
');
// Zeilen-Umbruch entfernen
Client.contentType := '
application/x-www-form-urlencoded';
Request.Client := Client;
Request.Response := Response;
Request.Method := rmPOST;
Request.AddParameter('
Authorization','
Basic ' + encoded, pkHTTPHEADER, [poDoNotEncode]);
Request.AddParameter('
grant_type','
refresh_token', pkGETorPOST, [poDoNotEncode]);
Request.AddParameter('
refresh_token',stcf.AccessData.RefreshToken, pkGETorPOST, [poDoNotEncode]);
Request.Execute;
MValue := response.JSONValue;
If MValue <>
NIL Then
begin
[...]
end;
finally
FreeAndNIL(Request);
FreeAndNIL(Response);
FreeAndNIL(Client);
end;
end;