B4J Question Google API search gives invalid url [SOLVED]

Tim Chapman

Active Member
Licensed User
Longtime User
When I paste the URL into my browser and go, it works, but in my code it does not.

When I run this code, I get an invalid url error:

B4J code:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    Dim client As HttpJob
    client.Initialize("cli",Me)

    'This works when I paste it into my browser and go:
    'https://www.googleapis.com/customsearch/v1?key=MYKEY&cx=MYCX&q=lectures"


    client.Download("https://www.googleapis.com/customsearch/v1?key=MYKEY&cx=MYCX&q=lectures")
    Wait For ResponseReceived_Complete
   
    'Wait For (client) Complete (Result As String)
    ' Result contains the search results in JSON format
    'Log("Result = " & Result)
End Sub

Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Log("Success")
    End If
   
    Log("Here1")
    Log("Job Done" & Job)
    Job.Release
    CallSubDelayed(Me, "ResponseReceived_Complete")
End Sub

This is a complete copy of the log:

WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
Success
Here1
Job Done[jobname=cli, success=true, username=
, password=, errormessage=, target=[root=(AnchorPane) AnchorPane@5141fc9f[styleClass=root], xui=anywheresoftware.b4a.objects.B4XViewWrapper$XUI@4ce91563, main=null
, b4xpages=null, b4xcollections=null, httputils2service=null
]
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@376c8736, response=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpResponse@64259b84
, tag=java.lang.Object@59939671, fx=anywheresoftware.b4j.objects.JFX@5dd5d22d, invalidurl=https://invalid-url/
, defaultscheme=https, main=null, b4xpages=null
, b4xcollections=null, httputils2service=null]
*** mainpage: B4XPage_Disappear [mainpage]

Any ideas?
 
Last edited:

teddybear

Well-Known Member
Licensed User
Where did you get an invalid url error?
In your log, you had got success, you can log Job.GetString to see the response result
 
Last edited:
Upvote 1
Solution

Tim Chapman

Active Member
Licensed User
Longtime User
That solves the problem. Thank you! This is my first time using http utils. Now I will sort out how to parse .json results.
Just to clarify for future readers, the invalid url error in the log of B4J seems to be irrelevant. The results still show as a nice .json result.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Thank you for letting me know about that. Does someone searching the forum or google see that the thread is "solved" somehow due to that check mark?
The checkmark will appear in the posts list beside the title of question.
It also contribute to number of correct solutions contributed by a member to show how helpful he is.
 
Upvote 0
Top