Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

roURLTranser not returning data

Hi there.  I'm having some trouble getting a roURLTransfer to send back data.  Specifically, I'm trying to get calendar events from a Google calendar using http GET.  When I copy and paste the URL into a web browser, I get data, but when I use the roURLTranser in Brightscript, I get nothing back.  I've tried both synchronously and asynchronously.  This is what I'm doing:

calendarBaseURL = "{0}/events?key={1}&fields=items(id,summary,start,end)&timeMin={2}&timeMax={3}&singleEvents=true&orderBy=startTime"
calendarID = ""
// I have tried URL encoding the whole thing.  Interestingly, the resulting URL does not even work in a web browser
// theURL = UrlEncode(substitute(calendarBaseURL, calendarID, calendarAPIKey, startTime.ToISOString(), endTime.ToISOString()))

// This URL has specific bits encoded as is done on the Google API documentation.  It works in a web browser but not here.
theURL = substitute(calendarBaseURL, url_encode(calendarID), url_encode(calendarAPIKey), url_encode(startTime.ToISOString()), url_encode(endTime.ToISOString()))

print "the URL = ";theURL

// This is the synchronous version (commented out presently):
// scheduleRequest = CreateObject("roUrlTransfer")
// scheduleRequest.SetURL(theURL)
// theRawData = scheduleRequest.GetToString()
// print "theRawData = ";theRawData

// Now for the asynchronous approach:

print "the URL that is being used =";xfer.getURL()

while true    
   msg=wait(100,port) // 100 millisecond pause
   if type(msg)="roUrlEvent" then

       if msg.getresponsecode()=200 then
           exit while
       end if
       // print "do something useful while we wait for data"   
   end if
   if timer.totalmilliseconds() > 2000 then
       ?"timeout exceeded"
       print "Failure Reason =";xfer.GetFailureReason()
       exit while
   end if
end while

When I run this, no data ever comes back. (FYI: I replaced all single-quote comments with "//" on here to make the auto syntax coloring not look weird.)  Interestingly, the synchronous version does not stall out, but rather the line that reads:

print "theRawData = ";theRawData

returns nothing but an empty string.

In the asynchronous version, a timeout happens but no failure reason is given.

The URL that is being sent looks like this:[ MY API KEY REMOVED ]&fields=items(id,summary,start,end)&timeMin=2016-11-03T07%3A38%3A03Z&timeMax=2016-11-03T19%3A38%3A03Z&singleEvents=true&orderBy=startTime

Now I've removed my API key in order to post this on a public forum, but if I were to copy and paste the returned URL with my API key into a web browser, I get lots of glorious data without a problem.

I haven't set any headers.  Could this be an issue?  Or security issues with Google in some way?  Any hints on what to look for?


0 Kudos
Level 11

Re: roURLTranser not returning data

To use https, you have to do some extra manual steps:

Why? ... because Roku.  8)
0 Kudos
Level 7

Re: roURLTranser not returning data

Wow, thanks for that - it works great!

Now that I've seen the answer, I know that I never would have figured that one out on my own and I've spent a lot of hours struggling with this to no avail.

Thank you so much; I really appreciate the help.

0 Kudos