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: 
rbenditt
Streaming Star

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 = "https://www.googleapis.com/calendar/v3/calendars/{0}/events?key={1}&fields=items(id,summary,start,end)&timeMin={2}&timeMax={3}&singleEvents=true&orderBy=startTime"
    
calendarID = "jmtf3oba4r2b8ca0tuse9qbj3s@group.calendar.google.com"
    
// 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:
xfer=createobject("roURLTransfer")
xfer.seturl(theURL)
xfer.SetRequest("GET")

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

port=createobject("roMessagePort")
xfer.setport(port)
timer=createobject("roTimeSpan")
timer.mark()
xfer.asyncgettostring()
while true    
   msg=wait(100,port) // 100 millisecond pause
   if type(msg)="roUrlEvent" then

       if msg.getresponsecode()=200 then
           data=msg.getstring()
           headers=msg.getresponseheadersarray()
           exit while
       else
           xfer.asynccancel()
       end if
   else
       // 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:
https://www.googleapis.com/calendar/v3/calendars/jmtf3oba4r2b8ca0tuse9qbj3s%40group.calendar.google.com/events?key=[ 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?

Thanks,

Ron
0 Kudos
2 REPLIES 2
EnTerr
Roku Guru

Re: roURLTranser not returning data

To use https, you have to do some extra manual steps:
xfer.SetCertificatesFile("common:/certs/ca-bundle.crt")
xfer.InitClientCertificates()

Why? ... because Roku.  😎
0 Kudos
rbenditt
Streaming Star

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.

Ron
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.