how to format "method" param for OAuth2 API calls in Ruby/RoR?

38 views
Skip to first unread message

Allen

unread,
Jun 16, 2015, 8:08:33 PM6/16/15
to rdio...@googlegroups.com
Hi - I've been trying to migrate my API calls to OAuth2 but I keep getting the response:

{"status"=>"error", "message"=>"You must pass a method name as an HTTP POST parameter named \"method\".", "code"=>400}


I'm using the oauth2 ruby gem (https://github.com/intridea/oauth2/blob/master/lib/oauth2/access_token.rb) and I can't seem figure out the right syntax.  


For example:
response = @access_token.post('/api/1/', {:method => 'search', :query => query, :types => types})

...I just get the error response above

the "post' method I'm using in the gem is:
def post(path, opts={}, &block)
      request
(:post, path, opts, &block)
end

I'm obviously not formatting the params correctly.  Any suggestions?

Thanks!

Devin Sevilla

unread,
Jun 17, 2015, 8:12:30 PM6/17/15
to rdio...@googlegroups.com
I'm not too familiar with Ruby, but it seems that the `opts` hash
needs to be different. Based on the documentation[1], I think you want
something like:

response = @access_token.post('/api/1/', {:body =>
'method=search&query=cher&types=artist'})

You need to pass the parameters in the body of the request. This
library expects a string, so you'll need to convert your hash of
method parameters to a form encoded string.

[1]: http://www.rubydoc.info/github/intridea/oauth2/OAuth2/Client#request-instance_method

--
Devin Sevilla
API Engineer, Rdio Inc.
http://rdio.com/people/devin_s/
> --
> You received this message because you are subscribed to the Google Groups
> "Rdio API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rdio-api+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rdio-api/141147cd-6ab4-443d-8939-97f38cd6cfa5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Allen

unread,
Jun 17, 2015, 9:08:38 PM6/17/15
to rdio...@googlegroups.com
Hey thanks, Devin! That was it.  Still getting a handle on OAuth2 and didn't realize it had to go into the body.  That did the trick :)
Reply all
Reply to author
Forward
0 new messages