I am very much new in working with roku and roku specific language( BasicScript ). I need to make api calls to some server to get the channels. I am not understanding how to do it in roku. Please suggest.
Asked
Active
Viewed 3,853 times
2 Answers
10
here is the direct way to do it without having to rely on the syntax of the code libraries that are included in your SDK:
Blocking Method (all program execution stops until the URL is retrieved):
url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML"
xfer=createobject("roURLTransfer")
xfer.seturl(url)
data=xfer.gettostring()
Non Blocking Method where you can do other things while waiting for data:
url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML"
xfer=createobject("roURLTransfer")
xfer.seturl(url)
port=createobject("roMessagePort")
xfer.setport(port)
timer=createobject("roTimeSpan")
timer.mark()
xfer.asyncgettostring()
while true
msg=wait(100,port) '100 millisecond pause
if type(msg)="roUrlEvent" then
if msg.getresponsecode()=200 then
data=msg.getstring()
headers=msg.getresponseheadersarray()
exit while
else
xfer.asynccancel()
end if
else
print "do something useful while we wait for data"
end if
if timer.totalmilliseconds() > 500 then
?"timeout exceeded"
exit while
end if
end while
print "***************HEADERS******************"
for each header in headers
print header
end for
print "***************DATA*********************"
print data
print "****************************************"

alphablender
- 2,168
- 5
- 27
- 42
-
1I am getting following Error BRIGHTSCRIPT: ERROR: roUrlTransfer: class PLUGIN|MARKUP on thread RENDER: – rkaartikeyan Feb 26 '17 at 21:40
-
Hello, @alphablender I required to display a dialog in `xfer.asynccancel()` Block, But Task node doesn't Support Dialog. Is there any way to display for dialog. I tried so much way using getparent() But not displaying yet. – Nikunj Chaklasiya Mar 12 '20 at 05:43
-
@NikunjChaklasiya best would be if you create a new question, short answer is use an observer for the a field updated by the task node to toggle the dialog on or off. – alphablender Mar 27 '20 at 22:46
0
http=NewHttp("http://server address")
rsp = http.GetToStringWithRetry()
print rsp 'To check the response text from server

user850234
- 3,373
- 15
- 49
- 83
-
This only works if you include the one of the URL utilties file from your SDK, for example url.brs from the TwitterOauth example. url.brs is a library of brightscript functions wrapping the roURLTransfer object, which adds a tiny bit of overhead in terms of execution time. – alphablender Nov 30 '12 at 00:04