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: 
mitchr181
Visitor

SetURL Not Setting URL

I have this code chunk that does an API request and should save the response to a file, but it doesn't. 'channel' is a String.
plReq = CreateObject("roURLTransfer")
plReq.AddHeader("Client-ID", *my API key*)
plReq.SetURL("https://usher.twitch.tv/api/channel/hls/" + channel + ".m3u8?player=twitchweb&token=" + resp.token.tostr() + "&sig=" + resp.sig.tostr() + "&allow_audio_only=true&allow_source=true&type=any&p=" + "7333049")

' configure SSL certs
plReq.SetCertificatesFile("common:/certs/ca-bundle.crt")
plReq.AddHeader("X-Roku-Reserved-Dev-Id", "")
plReq.InitClientCertificates()

code = plreq.GetToFile("tmp:/" + channel + ".m3u8")

When I look in the debugger, I see that code = -3, so I assumed that there was something wrong with the GET Request.
code             Integer val:-3 (&hFFFFFFFD)

I then tried to print the url associated with plReq to see if it was being set properly and it seems like the url string is empty
Brightscript Debugger> p plreq.geturl()


Brightscript Debugger> 

The only thing I can think of is that SetUrl() expects a String, not a roString. But I am unsure of how to convert the object back to an intrinsic as I need to be able to concatenate to build the url in the first place. Any help is appreciated.
0 Kudos
5 REPLIES 5
squirreltown
Roku Guru

Re: SetURL Not Setting URL

Just a guess, but .m3u8 is probably not a recognized extension. Try dropping it from the title and just use the channel var.  You actually don't need extensions when saving as far as the OS is concerned.
Kinetics Screensavers
0 Kudos
mitchr181
Visitor

Re: SetURL Not Setting URL

Just tried it, no dice. I also tried plreq.GetToString() just to see if there was any response at all, but the response string was empty and plreq.GetUrl() was also still empty.
code             roString (2.1 was String) refcnt=1 val:""
0 Kudos
squirreltown
Roku Guru

Re: SetURL Not Setting URL

try it this way. 

plreq.GetToFile("tmp:/" + channel)
code = readAsciiFile( "tmp/"+channel)
? code
Kinetics Screensavers
0 Kudos
mitchr181
Visitor

Re: SetURL Not Setting URL

plreq.gettofile("tmp:/" + channel)
code = readasciifile("tmp:/" + channel)

Brightscript Debugger> p code


Brightscript Debugger> 

Still nothing. Even though I'm using an old API, I don't think that's contributing to this problem. Even if the API was dead, I should still be able to see the url that I'm setting using plreq.geturl().
0 Kudos
speechles
Roku Guru

Re: SetURL Not Setting URL

     fileName = "tmp:/" + name
    LocalFileBrowser = CreateObject("roFileSystem")

    ' to read
    if LocalFileBrowser.exists(fileName)
        text = ReadAsciiFile(fileName)
    else
        text = ""
    end if
 
    ' to write
    WriteAsciiFile(filename,text)



plReq = CreateObject("roURLTransfer")



Are you doing this on the render thread? It almost seems like you are since you say the URL you set is empty. You must create a task to run URL transfers within.
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.