B4J Question How to extract text content from webview page ?

RushilD

Member
Licensed User
Hello All,

I am working on a simple test project where I load a login page using webview. This works file.

Currently I do the following:
1. Load a login page using webview
2. After successful login , the page displays the following text in the webview:

B4X:
{"expires_in":300,"refresh_expires_in":15551999,"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJjYjY5MzYyYi03NDYwLTQ5NmUtOTNiMS0yZTVjNDk1MDcxY2IifQ.eyJleHAiOjE3NDUyMTgwMDIsImlhdCI6MTcyOTY2NjAwMywianRpIjoiMzA2OWJjMTktNzkxYS00ZmZhLWEzZTQtZDU5ZmIwZTZiZjc1IiwiaXNzIjoiaHR0cHM6Ly9pZHAyLWFwaWd3LXByZXByb2QuY2xvdWQuZ3JvaGUuY29tL3YxL3Nzby9hdXRoL3JlYWxtcy9pZG0tYXBpZ3ciLCJhdWQiOiJodHRwczovL2lkcDItYXBpZ3ctcHJlcHJvZC5jbG91ZC5ncm9oZS5jb20vdjEvc3NvL2F1dGgvcmVhbG1zL2lkbS1hcGlndyIsInN1YiI6ImVhNjk1Y2IyLTRkMTUtNGRhZC1hOTlhLTk1YTFkY2I0ZjcyNCIsInR5cCI6IlJlZnJlc2giLCJhenAiOiJpb3QiLCJzZXNzaW9uX3N0YXRlIjoiOTRhNDEzMzctZGM4NC00ZjhlLWE2YzktZjg5N2Q2M2RiZTE4Iiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSIsInNpZCI6Ijk0YTQxMzM3LWRjODQtNGY4ZS1hNmM5LWY4OTdkNjNkYmUxOCJ9.j42m5A51NQauY_Z5ju9HbUtrbQa5E7kD2KGFGnzVdwo","token_type":"Bearer","id_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJUb1FBeE5QRFpMM1cxMVJkcGY3d1l2NjJfTUJrbmxKYlZrYTJxRm84RmRRIn0.eyJleHAiOjE3Mjk2NjYzMDMsImlhdCI6MTcyOTY2NjAwMywiYXV0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OYBYvLEJWc7YkHyd5FPiJ9kJiKHx066jH079qZpgfx6w","not-before-policy":0,"session_state":"94a41337-dc84-4f8e-a6c9-f897d63dbe18","scope":"openid profile","tandc_accepted":true,"partialLogin":false}


Question:
How can I extract the "refresh_token" and save it ?
 

Sagenut

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim refresh_token As String = jRoot.Get("refresh_token")
Dim partialLogin As String = jRoot.Get("partialLogin")
Dim refresh_expires_in As Int = jRoot.Get("refresh_expires_in")
Dim not-before-policy As Int = jRoot.Get("not-before-policy")
Dim scope As String = jRoot.Get("scope")
Dim id_token As String = jRoot.Get("id_token")
Dim token_type As String = jRoot.Get("token_type")
Dim session_state As String = jRoot.Get("session_state")
Dim tandc_accepted As String = jRoot.Get("tandc_accepted")
Dim expires_in As Int = jRoot.Get("expires_in")
 
Upvote 0

RushilD

Member
Licensed User

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim refresh_token As String = jRoot.Get("refresh_token")
Dim partialLogin As String = jRoot.Get("partialLogin")
Dim refresh_expires_in As Int = jRoot.Get("refresh_expires_in")
Dim not-before-policy As Int = jRoot.Get("not-before-policy")
Dim scope As String = jRoot.Get("scope")
Dim id_token As String = jRoot.Get("id_token")
Dim token_type As String = jRoot.Get("token_type")
Dim session_state As String = jRoot.Get("session_state")
Dim tandc_accepted As String = jRoot.Get("tandc_accepted")
Dim expires_in As Int = jRoot.Get("expires_in")

Thank you for the response but how do I extract the text from here:

I am calling
WebView1.LoadUrl("https://xxxxxxxxxxxxxxxxx/v3/test/login?getHttpLogin=true")

which opens a login page. I then enter the credentials. pressing login show the below text in the webview. Now I need to extract the contents

1729670368684.png
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
use okhttputils library

B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release
 
Upvote 0
Top