如何使API请求在Roku公司的一些服务器服务器、公司、API、Roku

2023-09-10 16:58:49 作者:摇铃唤白鹿

我在 Roku公司和Roku公司特定语言(BasicScript)的工作非常新。我需要API调用的一些服务器,以获取渠道。我不理解怎么做,在Roku公司。请建议。

解决方案

这里是直接的方式做到这一点,而不必依赖于包含在你的SDK中的code库的语法:

阻塞方法(所有程序执行停止,直到网址检索):

url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML" XFER = CREATEOBJECT(roURLTransfer) xfer.seturl(URL) 数据= xfer.gettostring()

非阻塞方法,你可以做其他的事情在等待数据:

url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML" XFER = CREATEOBJECT(roURLTransfer) xfer.seturl(URL) 端口= CREATEOBJECT(roMessagePort) xfer.setport(端口) 定时器= CREATEOBJECT(roTimeSpan) timer.mark() xfer.asyncgettostring() 而真正的     味精=等待(100口)100毫秒暂停     如果类型(MSG)=​​roUrlEvent再         如果msg.getresponse code()= 200,然后             数据= msg.getstring()             标题= msg.getresponseheadersarray()             退出而         其他             xfer.asynccancel()         如果结束     其他         打印做一些有用的东西,而我们等待数据     如果结束     如果timer.totalmilliseconds()> 500则         ?超时超标         退出而     如果结束 端,而 打印*************** HEADERS ****************** 在头每个标题 打印头 结束了 打印***************数据*********** 打印数据 打印 ****************************************

iPhone端,使用网络API 注册Api Api请求 解析JSON 素材 据经纬度查询天气

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.

解决方案

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 "****************************************"