Hi there
I have'nt used this yet, i'm curious about your ajax calls. This is my case scenario.
1. GetAccessToken - I save the retrieved access token to a file. I can save this to localstorage in this case using BANano I think.
2. Used the saved access token to return other data from the rest api...
Here is how I am currently using it.
Step 1:
Step 2: Subsequent
2. Next calls to the rest api, i pass an endpoint and a header bearer with the user token. I have a couple of API calls that work like this.
Question:
I just need advise on how I can perform this inside BANano AjaxCalls?
Thanks a lot.
I have'nt used this yet, i'm curious about your ajax calls. This is my case scenario.
1. GetAccessToken - I save the retrieved access token to a file. I can save this to localstorage in this case using BANano I think.
2. Used the saved access token to return other data from the rest api...
Here is how I am currently using it.
Step 1:
B4X:
'get the access token
Sub GetAccessToken() As ResumableSub
Log("GetAccessToken")
'set access token to blank
access_token = ""
Dim job As HttpJob
'initialize a http request
job.Initialize("",Me)
'pass the url to get the token
job.PostString("<endpoint>",$"grant_type=password&username=${userName}&password=${passWord}"$)
'set the content type
job.GetRequest.SetContentType("application/x-www-form-urlencoded")
'wait for the web service to complete
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
'translate to a map
Dim strResponse As String = job.GetString
job.release
Dim access As Map = Json2Map(strResponse)
'assign variables
access_token = access.GetDefault("access_token","")
expires_in = access.GetDefault("expires_in","")
'save the token to a file
File.WriteString(File.DirApp,"access_token.txt",access_token)
Return True
Else
If File.Exists(File.DirApp,accessTokenFile) Then File.Delete(File.DirApp,accessTokenFile)
LogError($"A '${job.ErrorMessage}' has been experienced reading GetAccessToken!"$)
job.Release
Return False
End If
End Sub
Step 2: Subsequent
2. Next calls to the rest api, i pass an endpoint and a header bearer with the user token. I have a couple of API calls that work like this.
B4X:
Sub ManyCallsLikeThis(ID As Int) As ResumableSub
Log("ManyCallsLikeThis")
'read the access token from file
ReadAccessToken
If access_token = "" Then Return False
'define command to read the province delimitation
Dim strCommand As String = $"<EndPoint>=${ID}"$
'create an http request
Dim job As HttpJob
job.Initialize("",Me)
job.Download(strCommand)
'pass the access token
job.GetRequest.SetHeader("Authorization", "bearer " & access_token)
'wait until the job is finished
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
'get the response
Dim strResponse As String = job.GetString
job.release
Dim Result As Map = Json2Map(strResponse)
'get the party results
Dim pr As List = Result.Get("pr")
For Each prmap As Map In pr
'do some things
Next
Return True
Else
LogError($"A '${job.ErrorMessage}' has been experienced reading the ManyCallsLikeThis!"$)
job.release
Return False
End If
End Sub
Question:
I just need advise on how I can perform this inside BANano AjaxCalls?
Thanks a lot.