Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make api request to some server in roku

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.

like image 481
user850234 Avatar asked Feb 24 '12 12:02

user850234


People also ask

What is Roku ECP?

The External Control Protocol (ECP) enables a Roku device to be controlled over a local area network by providing a number of external control services. The Roku devices offering these external control services are discoverable using SSDP (Simple Service Discovery Protocol).

What is bright script?

BrightScript is a powerful bytecode-interpreted scripting language optimized for embedded devices. In this way it is unique. For example, BrightScript and the BrightScript component architecture are written in 100% C for speed, efficiency, and portability.

Where is my Roku Channel ID?

To find your Channel ID, log into owner.roku.com and view your channel's properties. Your ID can be found in the address bar.


Video Answer


1 Answers

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 "****************************************"
like image 184
alphablender Avatar answered Oct 16 '22 16:10

alphablender