Page 1 of 1

Error from tsNetGetSync

Posted: Wed Mar 25, 2020 2:57 pm
by bmcgonag
I'm trying to call an API with tsNetGetSync based on a LiveCode Lesson I'm looking through. I have to send authorization as a header with a bearer token.

I read the token, and use that as a tHeader variable in my request, but when I run the code I get an error as follows:

Code: Select all

card "Home": execution error at line 8 (Function: error in function handler) near "tsNetGetSync", char 11
The code I'm running is as follows

Code: Select all

on preOpenCard
   put field APIToken on card "Settings" into apiToken
   if (apiToken = "") or (apiToken is empty) then
      -- just end here and wait.
   else
      put "https://my.zerotier.com/api/network" into apiUrl
      put "Authorization: bearer " && apiToken into apiHeader
      put tsNetGetSync(apiUrl, apiHeader, tRecvHeaders, tResult, tBytes) into tData
      
      if tResult is not 200 then 
         answer "Could not retrieve data" 
      else
         put tData into field apiReturndata
      end if
      
   end if
end preOpenCard
The error doesn't provide much in the way of what's wrong, and I'm afraid I don't have any idea since I'm following the lesson code for the API request as it is on screen.

Any help is greatly appreciated.

==========================================================

As a small update - I tried this lesson literally with no changes http://lessons.livecode.com/m/4071/l/84 ... a-web-site

And I get the following error:

Code: Select all

execution error at line 3 (Function: error in function handler) near "tsNetGetSync", char 8
Is there a way to verify if tsNetGetSync is included in the version I'm running of LiveCode? It's community edition 9.5.1

==========================================================

Update 2:

I tried some code to test if the connection was up and detected based on a thread lower down in this forum just using

Code: Select all

url("http://www.duckduckgo.com")
And it worked. So I am able to use URLs from LiveCode on this mac running catalina. But for some reason it's something about the tsNetGEt and / or tsNetGetSync functions that it seems to not like. Still digging, just not getting very far.

Re: Error from tsNetGetSync

Posted: Wed Mar 25, 2020 8:52 pm
by bmcgonag
Maybe I found my answer. The documentation in lessons doesn't specify which versions anything works on, so you just get to try it, fail with some obscure error, and not know why. I'm only guessing by a blog post from when tsNet was added, but it appears it's not available in community.

Thus it won't work. I don't mind at all making my code open source, but I can't use a falsely crippled system to build in. Back to VueJS and NeutralinoJS. Shame...and I get everyone needs to make money, but charge for support, or for Live or Online video lessons. Don't cripple what you've made. Just my opinion. LiveCode has some real promise. Maybe I'm wrong and there's just something weird with what I'm doing. Happy to find that out too.

Re: Error from tsNetGetSync

Posted: Wed Mar 25, 2020 9:01 pm
by Klaus
Yes, tsNet only comes with "paid" versions of Livecode: INDY and BUSINESS.

Re: Error from tsNetGetSync

Posted: Wed Mar 25, 2020 9:37 pm
by FourthWorld
bmcgonag wrote:
Wed Mar 25, 2020 8:52 pm
Maybe I found my answer. The documentation in lessons doesn't specify which versions anything works on, so you just get to try it, fail with some obscure error, and not know why. I'm only guessing by a blog post from when tsNet was added, but it appears it's not available in community.

Thus it won't work. I don't mind at all making my code open source, but I can't use a falsely crippled system to build in. Back to VueJS and NeutralinoJS. Shame...and I get everyone needs to make money, but charge for support, or for Live or Online video lessons. Don't cripple what you've made. Just my opinion. LiveCode has some real promise. Maybe I'm wrong and there's just something weird with what I'm doing. Happy to find that out too.
tsNet includes a few nice conveniences for HTTP, but is not necessary. Its main strength lies with other protocols.

All LiveCode editions support sockets, and LiveCode Community Edition includes libURL which provides good support for HTTP, HTTPS, and FTP.

Drop the tsNet syntax, look at POST and GET in the Dictionary (which are implemented in the LC engine in all editions), and let us know if you run into any snags.

For others down the road who may be similarly misled by incomplete tutorials discussing the edition-specific tsNet, I've submitted an enhancement request to clean up the Lessons on tsNet and expand the discussion to note libURL, which is not only available for all editions but has much cleaner, engine-integrated syntax:
https://quality.livecode.com/show_bug.cgi?id=22644

Re: Error from tsNetGetSync

Posted: Wed Mar 25, 2020 9:57 pm
by bogs
Nice ! :mrgreen:

Re: Error from tsNetGetSync

Posted: Wed Mar 25, 2020 10:33 pm
by bmcgonag
FourthWorld wrote:
Wed Mar 25, 2020 9:37 pm
...Drop the tsNet syntax, look at POST and GET in the Dictionary (which are implemented in the LC engine in all editions), and let us know if you run into any snags.

For others down the road who may be similarly misled by incomplete tutorials discussing the edition-specific tsNet, I've submitted an enhancement request to clean up the Lessons on tsNet and expand the discussion to note libURL, which is not only available for all editions but has much cleaner, engine-integrated syntax:
https://quality.livecode.com/show_bug.cgi?id=22644
First, thanks for the response. I appreciate the point in the right direction. I'll give libUrl a shot with GET and httpHeaders (it looks like).

Also, thanks for updating the documentation. Definitely helpful to know if certain functions will work with a given version.