Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mdesplanches
Visitor

Graph XML: use roUrlTransfer

Hello everyone,

I'm new on Roku plateform and I have some questions about XML component functionality !

I am getting a json with roUrlTransfer, and I printed correctly inside value.


Function getJson() As Object

searchRequest = CreateObject("roUrlTransfer")
searchRequest.SetCertificatesFile("common:/certs/ca-bundle.crt")
searchRequest.AddHeader("X-Roku-Reserved-Dev-Id", "")
searchRequest.InitClientCertificates()
searchRequest.SetURL("https://api.tfoumax.fr/catalog/home")
response = ParseJson(searchRequest.GetToString())

return response

End Function


But I wanted to use json response object in XML component file, like:


<?xml version="1.0" encoding="utf-8" ?>

<component name = "myrowlist" extends = "ContentNode" >

<script type = "text/brightscript" uri = "pkg:/source/getJson.brs" />

<script type="text/brightscript" >
<![CDATA[

sub init()

response = getJson()

end sub

]]>
</script>

</component>



But the program is stuck at response = getJson line, anyone have an alternative to use my json inside graph XML ?

Thanks in advance !

Max
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: Graph XML: use roUrlTransfer

You can't create an roUrlTransfer object in the main SceneGraph thread. You'll need to move that into a Task node.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
mdesplanches
Visitor

Re: Graph XML: use roUrlTransfer

Thanks your for your reactivity ! I am using now a task but it fail on SetCertificatesFile("common:/certs/ca-bundle.crt"), (not failed in brs file)

telnet:

Backtrace:
#0 Function init() As Void
file/line: ...AAA8F92yB/pkg:/components/getJson.xml(17)
Local Variables:
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=3 count:1
searchrequest Invalid



<?xml version="1.0" encoding="utf-8" ?>

<component name="getJsonGraph" extends="Task" >

<interface>
<field id="json-api" type="string" />
</interface>

<script type="text/brightscript" >
<![CDATA[

sub init()

searchRequest = CreateObject("roUrlTransfer")
searchRequest.SetCertificatesFile("common:/certs/ca-bundle.crt")
searchRequest.AddHeader("X-Roku-Reserved-Dev-Id", "")
searchRequest.InitClientCertificates()
searchRequest.SetURL("myapi-url")

response = ParseJson(searchRequest.GetToString())

For Each categorie In response.categories
print categorie.title
End For

end sub

]]>
</script>

</component>



Run task:

<?xml version="1.0" encoding="utf-8" ?>

<component name = "rowlistcontent" extends = "ContentNode" >

<script type="text/brightscript" >
<![CDATA[

sub init()

m.simpleTask = CreateObject("roSGNode", "getJsonGraph")
m.simpleTask.control = "RUN"

end sub

]]>
</script>

<children>

</children>

</component>


Thanks again for your help
0 Kudos
TheEndless
Channel Surfer

Re: Graph XML: use roUrlTransfer

For Task nodes, you need to set m.top.functionName in init(). That indicates which function will be run in the Task thread when you set the control to RUN. It's that function that will run in the separate thread and allow you to create the roUrlTransfer object.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
mdesplanches
Visitor

Re: Graph XML: use roUrlTransfer

Thanks you, it works !
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.