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: 
vlaine
Channel Surfer

Need help with Roku2 HLS : error 403

Can anybody help me.
I am trying to stream Tou.Tv HSL using their API
Here is the API doc: http://code.google.com/p/tou-tv-for-boxee/wiki/Api
 
First, I call http://api.tou.tv/v1/toutvapiservice.sv ... Repertoire to get the list of available TV Shows.
After choosing a show (I choose Decouverte Id=1361345422), I get the Show details
http://api.tou.tv/v1/toutvapiservice.sv ... 1361345422
 
Using the detail result, I take the show PID (in my example I am using Z5Dnri8bTt4u_FNkYcoWECqD7vYeddci) and get the HLS streaming Url
http://api.radio-canada.ca/validationMe ... utput=json
 
The result is json script with a url for the HLS streaming.
In my example, I got the following url, but if you try it, it will be already expired.
http://cp111857-f.akamaihd.net/i/004/mp ... 4c2429a26d
 
The resulting m3u8 file is:
 
Master.m3u8
 
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=250000, RESOLUTION=480x270
index_0_av.m3u8?e=b471643725c47acd
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=391000, RESOLUTION=480x270
index_1_av.m3u8?e=b471643725c47acd
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=491000, RESOLUTION=640x360
index_2_av.m3u8?e=b471643725c47acd
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=855000, RESOLUTION=640x360
index_3_av.m3u8?e=b471643725c47acd
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=1255000, RESOLUTION=852x480
index_4_av.m3u8?e=b471643725c47acd
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=62000, CODECS="mp4a.40.5"
index_0_a.m3u8?e=b471643725c47acd
 
When I try to stream the HLS url with my Roku, I receive an http error 403.
Can you help me find the problem ?
0 Kudos
21 REPLIES 21
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

I printed the m3u8 response I received on the Roku.
It is a little bit different from the one I receive on my PC.
Here is the printout

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=318000, RESOLUTION=480x270
index_0_av.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKC
KEIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=462000, RESOLUTION=480x270
index_1_av.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKC
KEIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=562000, RESOLUTION=640x360
index_2_av.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKC
KEIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=863000, RESOLUTION=640x360
index_3_av.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKC
KEIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=1326000, RESOLUTION=852x480
index_4_av.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKC
KEIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=62000, CODECS="mp4a.40.5"
index_0_a.m3u8?e=6303f0e8a89ec6bd&id=AgC4o%2fefGMjvrvkNbU9iPbNIEcHgJH5dyA5K4RKCK
EIIW6bVqHzIEM6GSCiC8feZXmxm0ic7PdpvaA%3d%3d
0 Kudos
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

here is an other log.
I need help please. I am out of ideas:

------ Running ------
showSpringboardScreen
VideoUrl:
http://cp143903-f.akamaihd.net/i/004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200...
5ebcc8
TargetIp: 24.200.239.203

Syslog Details
Http error: 403
Url: http://cp143903-f.akamaihd.net/i/004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200...
Status: httperror
OriginUrl: http://cp143903-f.akamaihd.net/i/004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200...
TargetIp: 24.200.239.138

Status: HTTP status 403

Request failed: Message: There was an error in the HTTP response. This could me
an that malformed HTTP headers or an HTTP error code was returned.
ErrorId: -1
Roku Internal Error : 0

Closing video screen
0 Kudos
TheEndless
Channel Surfer

Re: Need help with Roku2 HLS : error 403

I get a 403 when I try to access that URL in a browser as well, so the problem appears to be with however you're retrieving the URL. A 403 response is "Forbidden" which means your token is most likely expired or otherwise invalid. It could be a querystring encoding problem. Your URL has tildes (~) in it where it looks like there maybe should be ampersands (&). I'd review the API documentation to see if there's any mention of needing to do special unescaping of the returned URL/auth token.

Also, I see you're specifying JSON as the output. I'm not sure how you're parsing the JSON on the Roku, but it could also be a problem with that. Since they offer XML output, you're probably safer using it, since there's a built in XML parser that is infinitely faster and more accurate than the available JSON samples/parsers for BrightScript.
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
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

All the url above are expired. The cookie is short.
I posted them as an example.
Also, the url only works from Canada

The api only returns json responses.
I can parse the response no problem and get a valid video url.
This url already contains the cookie.
As you can see above, i can reach the master m3u8 file successfully.

The problem is with the inner m3u8.
When the Roku parse the master m3u8 file and try to get the inner m3u8 file I get an error 403.
It's as if the cookie was lost between the 2 calls.
0 Kudos
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

The master.m3u8 is a success

http://cp143903-f.akamaihd.net/i/004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200...

The Inner (or nested) m3u8 fails: index_4_av.m3u8

http://cp143903-f.akamaihd.net/i/004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200...

Note: the above url were valid for a limited time and are now expired. They are examples.
0 Kudos
TheEndless
Channel Surfer

Re: Need help with Roku2 HLS : error 403

"vlaine" wrote:
The api only returns json responses.
I can parse the response no problem and get a valid video url.

You are explicitly specifying "output=json" in the URL. If you change that to "output=xml" then it will return the results in XML. I have no doubt you can parse the JSON, but the available "SimpleJSON" libraries for BrightScript don't always decode the contents of the JSON, because they are not proper JSON parsers. My suggestion of using XML was to eliminate the possibility of there being invalid/unescaped characters in the URL value as a result of the JSON library you're using.

That aside, the 403 response is an indication that you're failing authentication, which would suggest that the authentication token is either mangled or otherwise not where it's expected to be. I see in your previous posts you have a "ReadCookies" function. Are you actually adding those cookies to the request via the roVideoScreen's ifHttpAgent? The Roku doesn't support cookies natively, so if the M3U8s require the cookie to be present and you're not adding them to the headers, that could be your problem.
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
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

This request only support json:
http://api.tou.tv/v1/toutvapiservice.svc/json/GetPageRepertoire

But you are right about this one, I will try with xml
[url]http://api.radio-canada.ca/validationMedia/v1/Validation.html?appCode=thePlatform&deviceType=iphone4&connectionType=wifi&idMedia=Z5Dnri8bTt4u_FNkYcoWECqD7vYeddci&output=json[/url]

The m3u8 requires Cookies.
The master url already includes the cookie
http://cp111857-f.akamaihd.net/i/004/mp4/d/2012-03-04_18_30_00_dec_3019_,256,400,500,800,1200,.mp4.c...


This portion of the url is the cookie
hdnea=expires%3D1332524151~access%3D%2Fi%2F004%2Fmp4%2Fd%2F2012-03-04_18_30_00_dec_3019_*~md5%3D0e6ec02682015d53a4ebef4c2429a26d

When I read the cookie, here is the result:
    **********************************************************
    Function ReadCookies(videoUrl)
    **********************************************************

    Headers
    connection: close
    set-cookie: _alid_=j36jjnPsegnLAxaFnJaTkQ==; path=/i//004/mp4/a/2012-03-13_20_00
    _00_apparences_0010_,256,400,500,800,1200,.mp4.csmil/; domain=cp143903-f.akamaih
    d.net
    cache-control: no-store
    date: Thu, 29 Mar 2012 02:42:54 GMT
    content-length: 1183
    pragma: no-cache
    content-type: application/vnd.apple.mpegurl
    mime-version: 1.0
    server: AkamaiGHost
    expires: Thu, 29 Mar 2012 02:42:54 GMT


    Cookies:
    Cookie #1:
    hdntl=exp=1333075374~acl=%2f*~data=hdntl~hmac=ff6d7a5cf04011acbe0113c0b707d1ac14
    efdad1758c6f17c499983d802515ec; path=/; domain=cp143903-f.akamaihd.net;

    Cookie #2:
    _alid_=j36jjnPsegnLAxaFnJaTkQ==; path=/i//004/mp4/a/2012-03-13_20_00_00_apparenc
    es_0010_,256,400,500,800,1200,.mp4.csmil/; domain=cp143903-f.akamaihd.net


Do I still have to set cookie myself ?
I was not sure so I tried like this, but it didn't work:

    p = CreateObject("roMessagePort")
    video = CreateObject("roVideoScreen")
    video.setMessagePort(p)

    videoclip = CreateObject("roAssociativeArray")
    videoclip.StreamBitrates = [0]
    videoclip.StreamUrls = [videoUrl]
    videoclip.StreamQualities = ["SD"]
    videoclip.StreamFormat = "hls"
    videoclip.Title = "Tou.TV test video"

    ' Read Cookies
    cookies = ReadCookies(videoUrl)

    ' ReadCookies() result:
    ' Cookie #1:hdntl=exp=1333075374~acl=%2f*~data=hdntl~hmac=ff6d7a5cf04011acbe0113c0b707d1ac14efdad1758c6f17c499983d802515ec; path=/; domain=cp143903-f.akamaihd.net;
    ' Cookie #2:_alid_=j36jjnPsegnLAxaFnJaTkQ==; path=/i//004/mp4/a/2012-03-13_20_00_00_apparences_0010_,256,400,500,800,1200,.mp4.csmil/; domain=cp143903-f.akamaihd.net

    ' Manually add cookies
    for each cookie in cookies
      video.AddHeader("Cookie", cookie)
    next

    video.SetContent(videoclip)
    video.show()


Maybe I am doing something wrong. Am I correctly adding cookies ?
Do I really have to add cookies since they are already in the url ?
0 Kudos
vlaine
Channel Surfer

Re: Need help with Roku2 HLS : error 403

This article talks about Tou.TV Cookies.
https://groups.google.com/forum/?fromgr ... 8txKLJq0Jg

I hope it can help somebody help me.
0 Kudos
belltown
Roku Guru

Re: Need help with Roku2 HLS : error 403

I think you're incorrectly returning the cookies to the server.

The server sends Set-Cookie headers, one for each cookie, with attribute-value pairs that apply to that particular cookie, separated by semicolons, e.g:

Set-Cookie: cookie1name=cookie1value; path=pathname; domain=domainname
Set-Cookie: cookie2name=cookie2value; path=pathname; domain=domainname

When you return the cookies to the server you have to extract the name-value pairs only (not the attribute-value pairs) for each cookie and return the list of cookies in a "Cookie:" header where the cookies themselves (not the attributes for each cookie) are separated by semicolons, e.g.:

Cookie: cookie1name=cookie1value1; cookie2name=cookie2value


EDIT: I don't think that's the reason why you're getting the 403 error, however. I agree with TheEndless that it's most likely a URL encoding issue.
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.