B4J Question Dialogflow integration

yaqoob

Active Member
Licensed User
Longtime User
Hello everyone

I am trying to integrate google Dialogflow through the API REST as per the instructions in the document Quickstart: Interactions with the API. The Dialogflow requires to use GoogleOAuth2. It requires getting a token and then using the token to get the results. I tried with the example Google Play Developer API for the tokin, but the logs show "Cannot show from server!!!" and stopes.
Any suggestion that helps is appreciated.

Thank you.
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
I think that the first step is to start with an interactive test to see your Google setup is correct. Sadly you don't give any program example information so we have guess how you do it. Google authentication requires additional settings to use it with SSL and certificates in webview as an example. I give a working SSL example in my post SMTP send mail issue from outlook.
 
Upvote 0

yaqoob

Active Member
Licensed User
Longtime User
The below code I am using to get the token from the example GoogleOAuth2. if I run it for the first time the log show "Cannot show from server!!!". If I run it for the 2nd time the log shows "(BindException) java.net.BindException: Address already in use (Bind failed)" and "Cannot show from server!!!". I have already set up a service account in Google and I used my client id and client secret.

B4X:
Sub Class_Globals
    Private mreq As ServletRequest        'ignore
    Private mresp As ServletResponse    'ignore
    Private oauth2 As GoogleOAuth2
    
End Sub

Public Sub Initialize
    
    oauth2.Initialize(Me, "oauth2", Main.ClientId, "https://www.googleapis.com/auth/dialogflow", _
        Main.ClientSecret, Main.DataFolder)
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    
    
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, Token As String)
    If Success = True Then

        Log(Token)
    Else
    
        Return
    
    End If


End Sub
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
The first error message seems to indicate that a connection to Google is being established, but that the authentication was not successful. That explains the two error because that connection is already in use.

It's been a while since I've been working with the SMTP example to get it working. But I don't see anywhere in the example how to arrange the SSL certificates and the additions in HTTPS headers. If the wrong (default) SSL setting is used during the connection, the authentication will fail. I think this happened with your program code
 
Upvote 0

yaqoob

Active Member
Licensed User
Longtime User
Thank you MicroDrie for your feedback. I have added the ConfigureSSL model, but still, the issue is the same. Please find attached the program
 

Attachments

  • Dailog.zip
    4.4 KB · Views: 193
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

yaqoob

Active Member
Licensed User
Longtime User
Thank you DonManfred for your suggestion. I tried to use UI APP as your suggestion, I go the below error.

dailogflowerror.jpg
 
Upvote 0

yaqoob

Active Member
Licensed User
Longtime User
The issue is that GoogleOAuth2 works only with OAuth 2.0 Client IDs. It does not work with Service Accounts. In my case, I am looking for tokens generated through a service account. I have been searching in google documents for days. The solution google support suggested is using Google Cloud Client Libraries.
Any suggestion on how to use Google Cloud Client Libraries in B4J or any other solution using Service Accounts

Thank you
 
Upvote 0

yaqoob

Active Member
Licensed User
Longtime User
I solved the problem. Migrated from Google Dialogflow to the Microsoft Azure bot. It is much easier to integrate. I hope in the coming days there will be a solution using B4j and google service accounts.
 
Upvote 0
Top