Your Digital Media Has Never Looked So Good

 
mitchr181
Topic Author
Posts: 5
Joined: Sat Jun 08, 2019 5:31 am

SetURL Not Setting URL

Sat Jun 08, 2019 7:52 am

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.
 
User avatar
squirreltown
Posts: 870
Joined: Sun Apr 21, 2013 2:20 pm

Re: SetURL Not Setting URL

Sat Jun 08, 2019 8:16 am

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
 
mitchr181
Topic Author
Posts: 5
Joined: Sat Jun 08, 2019 5:31 am

Re: SetURL Not Setting URL

Sat Jun 08, 2019 8:27 am

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:""
 
User avatar
squirreltown
Posts: 870
Joined: Sun Apr 21, 2013 2:20 pm

Re: SetURL Not Setting URL

Sat Jun 08, 2019 8:43 am

try it this way. 

plreq.GetToFile("tmp:/" + channel)
code = readAsciiFile( "tmp/"+channel)
? code
Kinetics Screensavers
 
mitchr181
Topic Author
Posts: 5
Joined: Sat Jun 08, 2019 5:31 am

Re: SetURL Not Setting URL

Sat Jun 08, 2019 9:02 am

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().
 
User avatar
speechles
Posts: 169
Joined: Thu Aug 06, 2015 11:15 pm

Re: SetURL Not Setting URL

Sat Jun 08, 2019 9:53 am

     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.

Who is online

Users browsing this forum: No registered users and 11 guests