Hey!
I'm working with my API made in PHP . Afer I got logged it returns an Access Token and a Refresh Token in json format. Like this:
Postman:
With B4A I'm doing this to return to my app that data
This returns:
'till here everything works fine... But I need to work and handle that response (work with access token etc..)
To do that I'm trying to do this..
But.. it doesn't work.. I got this error log...
and I don't know what I'm doing wrong! Thank you in advance!!!
I'm working with my API made in PHP . Afer I got logged it returns an Access Token and a Refresh Token in json format. Like this:
Postman:
B4X:
{
"statusCode": 201,
"success": true,
"messages": [],
"data": {
"session_id": 9,
"access_token": "ZDk0M2E2OGMwZjQ2OGVhNWE3YTUwY2E1OWJjODZkNmQ4NzhmMjAwMzFmNDEzOGIyMTY0MDMwNjA3NA==",
"access_token_expires_in": 1200,
"refresh_token": "MzQ5ODg0ZGFhYjNjNjUwNWMwOTFhZTY0OGNkODJlZTUxNWQ1Mzc3NmExYjc0YWY5MTY0MDMwNjA3NA==",
"refresh_token_expires_in": 1209600
}
}
With B4A I'm doing this to return to my app that data
B4X:
Dim ok As HttpJob
ok.Initialize("",Me)
ok.PostString(endpointUrl,data)
ok.GetRequest.SetContentType("application/json")
Wait For (ok) Jobdone(ok As HttpJob)
If ok.Success Then
Log(ok.GetString)
Log("DATA SENT TO SERVER RESPONSE SUCCESS")
B4X:
This returns:
B4X:
{"statusCode":201,"success":true,"messages":[],"data":{"session_id":65,"access_token":"NTE3NzUzZmU3Yjk4ZDdjMmQ1YmQ0MzZjYzE0NThmMzBiNDhhZTBjOGJiMmUwYmU3MTY0MDM4NTAwOA==","access_token_expires_in":1200,"refresh_token":"YmY5YWYyYWI4OTQyOGMyOWI5YzE5YjBjYmY2NTAzNGY0YTc1YWM2NTMwN2Y0YzVlMTY0MDM4NTAwOA==","refresh_token_expires_in":1209600}}
'till here everything works fine... But I need to work and handle that response (work with access token etc..)
To do that I'm trying to do this..
B4X:
Dim parser As JSONParser
parser.Initialize(ok.GetString)
Dim mRoot As Map = parser.NextObject
Dim datos As List = mRoot.Get("data")
For Each resl As Map In datos
Dim SessionID As Int = resl.Get("session_id")
Dim AT As String = resl.Get("access_token")
Dim RT As String = resl.Get("refresh_token")
Dim T_EXPIRES As Float = resl.Get("access_token_expires_in")
Dim row(4) As Object
row(0) = SessionID
row(1) = AT
row(2) = RT
row(3) = T_EXPIRES
'datasessionlist.Add(row)
Log(datos)
Log("-----------")
Log(AT)
Log("-----------")
Log(RT)
Log("-----------")
Log(T_EXPIRES)
Log("---FIN DE LOS DATOS----")
Next
But.. it doesn't work.. I got this error log...
B4X:
Error occurred on line: 141 (Main)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
and I don't know what I'm doing wrong! Thank you in advance!!!
Last edited: