Hi,
Trying to adapt : https://www.b4x.com/android/forum/t...y-authorisation-requirement.81048/post-513901
with (for Base64Encode) : https://www.b4x.com/android/forum/threads/xui-sd-base64-encode-decode.105755/post-662153
I get for authentication (job1) : {"error":"invalid_client"}
I can't find lot of help on G nor on spotify docs
Someone has advice or can point where the error is ?
Or a running example ...
Maybe while encoding in base64 ... I didn't find such function in standard jLibs ....
Thanks in advance
here is the code
Trying to adapt : https://www.b4x.com/android/forum/t...y-authorisation-requirement.81048/post-513901
with (for Base64Encode) : https://www.b4x.com/android/forum/threads/xui-sd-base64-encode-decode.105755/post-662153
I get for authentication (job1) : {"error":"invalid_client"}
I can't find lot of help on G nor on spotify docs
Someone has advice or can point where the error is ?
Or a running example ...
Maybe while encoding in base64 ... I didn't find such function in standard jLibs ....
Thanks in advance
here is the code
B4X:
Private Sub btnTest01_Click
SpotGrant1 = "client_credentials"
SpotClientID1 = "checked twice on spotify console" 'Use your own Spotify Client ID!
SpotClientSecret1 = "checked twice on spotify console" 'Use your own Spotify Client Secret key!
SourceWeb1 = "https://accounts.spotify.com/api/token"
Private s1 As String = Base64Encode(SpotClientID1)
Private s2 As String = Base64Encode(SpotClientSecret1)
SpotBase64 = s1&":"&s2
'SpotBase64 = B64.EncodeStoS(SpotClientID1 & ":" & SpotClientSecret1,"UTF8")
Log(SpotBase64)
Job1.Initialize("Job1", Me)
Job1.PostString(SourceWeb1, "grant_type=" & SpotGrant1)
Job1.GetRequest.SetContentType("application/x-www-form-urlencoded")
Job1.GetRequest.SetHeader("Authorization", "Basic " & SpotBase64)
End Sub
Sub JobDone (Job As HttpJob) 'Event
Dim n As Long
Dim m As Long
If Job.Success = True Then
Select Job.JobName
Case "Job1"
SourceText1 = Job.GetString2("ISO-8859-1")
n=SourceText1.IndexOf2(":",0)+2 'Dubbele punt en aanhalingsteken moeten weg!
m=SourceText1.IndexOf2(Chr(34),n+8)
SpotToken1=SourceText1.SubString2(n,m)
Log("Token=" & SpotToken1)
SpotQuery1 = "frank+sinatra+my+way"
SourceWeb1 = "https://api.spotify.com/v1/search?query=" & SpotQuery1 & "&type=track&access_token=" & SpotToken1 & "&token_type=Bearer&expires_in=3600" '&limit=1
Job2.Initialize("Job2", Me)
Job2.Download(SourceWeb1)
Job.release
Return
Case "Job2"
SourceText1 = Job.GetString2("ISO-8859-1")
n=0
n=SourceText1.IndexOf2("spotify:track:",0)+14 'With multiple results this might not always be the desired song and thus deeper analysis of the JSON will be needed.
m=SourceText1.IndexOf2(Chr(34),n)
If n<14 Or m<=n Then Return
SpotTrack1=SourceText1.SubString2(n,m)
Log(SpotTrack1)
'Dim Intent1 As Intent
'Intent1.Initialize(Intent1.ACTION_VIEW, "spotify:track:" & SpotTrack1)
'Intent1.SetComponent("com.spotify.music")
'StartActivity(Intent1)
Job.Release
Return
End Select
Else
Log("Error in " & Job.JobName & ": " & Job.ErrorMessage)
End If
End Sub