How to Curl for text messaging

byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: How to Curl for text messaging

Post by byron.hopp »

I have switched to Twilio, cut all ties with EZTexting and utilizing the code you all provided I can send a text. Thank you. However my program shuts down upon the return statement. What do I need in the Mak file for cUrl. I have currently LibCurl.lib, and hbcurl.lib in the .mak, I include hbcurl.ch in my program, and I have libcurl.dll in the application directory.
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: How to Curl for text messaging

Post by reinaldocrespo »

If the program successfully sends texts via Twilio and then you get a runtime error when closing, the problem is most likely in your code and it has nothing to do with your make file. Try finding the exact line that causes de GPF or write and share a reduced sample code that replicates the runtime error.
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: How to Curl for text messaging

Post by byron.hopp »

Here is my code, modified yours a little. Had to use my logging function. Using the Twilio API seems to work great, it the crashing of the program I can't figure out. Thanks, in advance. Line number in the hb_out.log file leads me to the "Return nil" statement. Error 6005: Exception error:

Function TwilioText( cTel_To,cBody )
Local cLogFile := "TraceLog.txt"
Local hCurl
Local nError
Local Httpcode
Local cUrl := "https:" + "/" + "/" + "api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json"
Local cPostFields := 'To=' + cTel_To + chr(38) + "From=" + TEL_FROM + chr(38) + "Body=" + Time() + " " + cBody
Logit( cLogFile, Replicate( "-", 80 ) )
Logit( cLogFile, curl_version() )
Logit( cLogFile, cPostFields )
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )
curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, 1 )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
nError := curl_easy_perform( hCurl )
curl_easy_getinfo( hCurl, HB_CURLINFO_RESPONSE_CODE, @Httpcode )
Logit( cLogFile, "HttpCode =", nAllTrim( HttpCode ) )
if nError = HB_CURLE_OK
Logit( cLogFile, "SMS sent succesffully" )
Logit( cLogFile, curl_easy_dl_buff_get( hCurl ) )
elseif Httpcode != 200 .AND. Httpcode != 201
Logit( cLogFile, { "SMS send failed, HTTP Status Code ", Httpcode } )
else
Logit( cLogFile, curl_easy_strerror( nError ) )
endif
endif
curl_global_cleanup()
Return nil
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: How to Curl for text messaging

Post by reinaldocrespo »

curl_global_init() and curl_global_cleanup() should be called only once in the program. Throw them away from the function.

Have a main function as an entry point. For example: Main(). And from that Main() entry point call curl_global_init.... then call your function as many times as needed. Then before exiting main() func, call curl_global_cleanup().

When sharing code it works best if sent as otherwise it is hard to follow as you loose all indentation. Just my 2 cents.
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: How to Curl for text messaging

Post by byron.hopp »

Your 2 (two) cents is golden. I have been on this board for more years that I would like to admit and I never knew how to do that. I will try to remember. I am going to try your fix now. Thanks,
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: How to Curl for text messaging

Post by byron.hopp »

Worked great, thank you my friend...
Thanks,
Byron Hopp
Matrix Computer Services
Post Reply