B4J Question Creating a simple java b4j library

shhammer5634

Member
Licensed User
Longtime User
This may require some explanation so bear with me please:

I need to send text message from b4j though Twilio. Twilio offers a java client and has some example code to get one started. Using the a modified version of that sample java code, I used the SimpleLibraryCompiler to create a library. I am not a java programmer, so the fact that I may have missed something is highly likely. I managed, using the SLC to get a compiled library with a method and several properties. I went through the XML file and filled in some comments and a short name. It shows up as a library in b4j, and I am able set up the properties, etc. in b4j. However, when I go to compile the sample b4j program, I get this:

B4J Version: 6.51
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.00s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
javac 1.8.0_191
src\b4j\sms\main.java:47: error: cannot find symbol
public static Twiliosms _sms = null;
^
symbol: class Twiliosms
location: class main
1 error​

At this point, the b4j program is very simple. I just was trying to prove whether my library worked or not. Can someone point me in the right direction of things I should be looking at?

Thanks much
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I have used SLC, it is nice and awesome.

BUT!! If you do not know Java it is not the right tool for you. You should really try JavaObject.

Also. If you have the link to the library and the javadocs it would me much easier to help you.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Twillio does provide a HTTP REST Api. You most probably use it directly using okhttputils2. no need for a library. No need for java knowledge to create a library.
https://www.twilio.com/docs/sms/api
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
I have used SLC, it is nice and awesome.

BUT!! If you do not know Java it is not the right tool for you. You should really try JavaObject.

Also. If you have the link to the library and the javadocs it would me much easier to help you.
Enrique,

Thanks for replying to my post. After I made it, I put on Eclipse and tried to compile their full, unmodified, example code. I couldn't get it to compile. So you're right that it's probably not the correct way for me to go. If I decide to go through JavaObject using their jar file I'll re-post with the information you've suggested. But for now I think I'm going to try DonManfred's suggestion.

I appreciate your willingness to help.

Steve
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
Twillio does provide a HTTP REST Api. You most probably use it directly using okhttputils2. no need for a library. No need for java knowledge to create a library.
https://www.twilio.com/docs/sms/api
As usual DonManfred, your answer is on point. I saw that they had the REST Api, but I really wanted to try my hand at a Java library. I have other things I want to try and wrap and I thought this might be a simple place to start. But as usual, I was wrong. I'll give the REST Api a go.

As always, thanks for your help.

Steve
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but I really wanted to try my hand at a Java library.
You should try to start with a simpler SDK. The Twilio Java SDK is not an easy SDK. It depends on some other things.
Probably a very difficult job if you have no java and library wrapping experience!
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
You should try to start with a simpler SDK. The Twilio Java SDK is not an easy SDK. It depends on some other things.
Probably a very difficult job if you have no java and library wrapping experience!
Thanks. I will give it a go for sure. For the record I was able to figure out how to send an sms through Twilio using their REST API and okHttpUtils2 PostString method.

Below is a condensed, modified, and redacted version of what I did. To use this code you would need the okHttpUtils2 library included in your project

B4X:
Sub SendMessage(PhoneNumber As String, Message As String)

    Dim SID As String = "<Your Twilio SID Here>"
    Dim TOKEN As String = "<Your Twilio AUTH_TOKEN Here>"
    Dim MYPHONE As String = "<Your Purchased Twilio Phone Number Here>"
    Dim SIG As String '(Optional signature for outgoing text message)
    Dim job As HttpJob

    job.Initialize("",Me)
    job.Username = SID
    job.Password = TOKEN

    job.PostString("https://api.twilio.com/2010-04-01/Accounts/<Your Twilio SID Here>/Messages.json", "From=" & MYPHONE & "&To=" & PhoneNumber & "&Body=" & Message & SIG)
    Wait For (job) JobDone(job As HttpJob)

    If job.Success Then
        Log(job.GetString)
       Else
         'Error processing code here
    End If

    job.Release

End Sub

If someone wanted to process what's returned when the message has been submitted they could process what's returned in job.GetString

I really do appreciate your help.
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
This may require some explanation so bear with me please:

I need to send text message from b4j though Twilio. Twilio offers a java client and has some example code to get one started. Using the a modified version of that sample java code, I used the SimpleLibraryCompiler to create a library. I am not a java programmer, so the fact that I may have missed something is highly likely. I managed, using the SLC to get a compiled library with a method and several properties. I went through the XML file and filled in some comments and a short name. It shows up as a library in b4j, and I am able set up the properties, etc. in b4j. However, when I go to compile the sample b4j program, I get this:

B4J Version: 6.51
Parsing code. (0.00s)
Building folders structure. (0.01s)
Compiling code. (0.00s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
javac 1.8.0_191
src\b4j\sms\main.java:47: error: cannot find symbol
public static Twiliosms _sms = null;
^
symbol: class Twiliosms
location: class main
1 error​

At this point, the b4j program is very simple. I just was trying to prove whether my library worked or not. Can someone point me in the right direction of things I should be looking at?

Thanks much

Twilio??? do that yourself with python library -> https://github.com/tgalal/yowsup
i did i learn and its working.

Victor
 
Upvote 0

shhammer5634

Member
Licensed User
Longtime User
You could try me demo, please send me PM.

victor
Thank you Victor. Congratulations on getting it going in Python. I may try that in the future. However changing languages in the middle of a development cycle is usually not a good idea. At least for me. Just as I am not a Java programmer, I am not a Python programmer either.

Steve
 
Upvote 0
Top