Roku Developer Program

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

Need help with cUrl on roku

This works just fine from command line.

curl 'https://api.blah.com/ath/link' \
-d 'client_id=lOnGStringOfCharacters' \
-d 'client_secret=reallyreallylongstringofcharacters' \
-d 'grant_type=password' \
-d 'username=blabla@blababla.com' \
-d 'password=s0mth1ng'
-d 'redirect_uri=http://myblah.com/fail'


Any suggestions on how to convert this into a url to POST and or GET using roURlXfer?

Would the \ be converted to an ampersand? or the -d ? I tried putting it all on one line with ampersands and it was no-go, whereas cUrling it worked perfectly.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
3 REPLIES 3\
TheEndless
Level 9

Re: Need help with cUrl on roku

Yes, with an "&". The POST string should look pretty much identical to a querystring, without the leading "?". Note that, typically, it should also be URL encoded like a querystring, as well.

urlTransfer = CreateObject("roUrlTransfer")
urlTransfer.SetUrl("https://api.blah.com/ath/link")
urlTransfer.AddHeader("Content-Type", "application/x-www-form-urlencoded")
result = urlTransfer.PostFromString("client_id=lOnGStringOfCharacters&client_secret=reallyreallylongstringofcharacters&grant_type=password&username=blabla%40blababla.com&password=s0mth1ng&redirect_uri=http%3a%2f%2fmyblah.com%2ffail")
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
jbrave
Level 8

Re: Need help with cUrl on roku

Hi Endless, thanks.

One more question: how do I get the response information from this POST? postfromstring just returns an integer, not the response info I get with cUrl on the command line.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
RokuKevin
Level 9

Re: Need help with cUrl on roku

Use the Async version to get more detailed info returned....

From the event below you could query for the info you want like GetResponseHeadersArray()

--Kevin

Example:

Function http_post_from_string_with_timeout(val As String, seconds as Integer) as String
timeout% = 1000 * seconds

str = ""
' m.Http.EnableFreshConnection(true) 'Don't reuse existing connections
if (m.Http.AsyncPostFromString(val))
event = wait(timeout%, m.Http.GetPort())
if type(event) = "roUrlEvent"
print "1"
str = event.GetString()
elseif event = invalid
print "2"
Dbg("AsyncPostFromString timeout")
m.Http.AsyncCancel()
else
print "3"
Dbg("AsyncPostFromString unknown event", event)
endif
endif

return str
End Function
0 Kudos