cobaia O60629

Member since: Saturday, 10 March 2018
Last login: 3 months ago
Profile viewed: 58 views

No Rank
Points: 0

cobaia O60629 created a new topic ' Spotify API Client Credentials Flow' in the forum. 3 months ago

Can anyone help me use http with sporify?
I do not know where I'm going wrong! = \

I'm trying to use this authentication:
developer.spotify.com/web-api/authorization-guide/

I got some examples in C #:

sample 1
gist.github.com/lqdev/5e82a5c856fcf0818e0b5e002deb0c28

sample 2
gist.github.com/aaronhoffman/6383054e14427a22ddc11045f53b0e6e

I'm trying to port to delphi, but I'm not succeeding, could you help me? just put an idhttp and paste the code below

Note: when it is working, I delete the app I created in spotify, because the keys below are real!

my code (not work):

uses: System.NetEncoding

var
URL, valor: string;
SpotifyClientID, SpotifyClientSecret: string;
JsonStreamEnvio: TStringStream;
begin
URL := ' accounts.spotify.com/api/token ';
JsonStreamEnvio := TStringStream.Create('grant_type, client_credentials', TEncoding.UTF8);

idHttp.Request.Clear;
idHttp.Request.CustomHeaders.Clear;
idHttp.Request.ContentType := 'application/json';
IdHttp.Request.CharSet := 'utf-8';

SpotifyClientID := 'babf60d97d954cc089fa26e28ffb1bb7';
SpotifyClientSecret := 'da28e5d2f32945069928f9d6d7e2f258';
valor := SpotifyClientID+':'+SpotifyClientSecret;
valor := TNetEncoding.Base64.Encode(valor);

idHttp.Request.CustomHeaders.AddValue('Authorization', 'Basic '+valor);
idHttp.Response.CharSet := 'UTF-8';

try
idHttp.Post(URL, JsonStreamEnvio);
except
on E:EIdHTTPProtocolException do
ShowMessage(e.ErrorMessage);
end;

Read More...