Using Ruby + OAuth to Access the Yelp API

I am just starting out with OAuth and I was trying to make a small client to connect to some web services ... I tried twitter and it worked like a charm, however I also tried to access the Yelp V2 API (after their Python example), but I always come back to answers: HTTP 400 Bad Request

Missing parameter: oauth_consumer_key

Here is my code:

require 'rubygems' require 'oauth' CONSUMER_KEY = "MY_CONSUMER_KEY" SECRET = "MY_CONSUMER_SECRET" TOKEN = "MY_TOKEN" TOKEN_SECRET = "MY_TOKEN_SECRET" consumer = OAuth::Consumer.new( CONSUMER_KEY,SECRET, {:site => "http://api.yelp.com", :signature_method => "HMAC-SHA1", :scheme => :header}) access_token = OAuth::AccessToken.new( consumer, TOKEN,TOKEN_SECRET) p access_token.get("/v2/search?location=new+york").body 

Regardless of the fact that this code works with twitter API without any problems (I really followed the example of Twitter code)

Greetings and thanks in advance, Ze

+4
source share
2 answers

Use: query_string instead of: header and everything will work (at least for me).

+2
source

The same code using Signet :

 require 'signet/oauth_1/client' client = Signet::OAuth1::Client.new( :consumer_key => 'MY_CONSUMER_KEY', :consumer_secret => 'MY_CONSUMER_SECRET', :access_token_key => 'MY_TOKEN_KEY', :access_token_secret => 'MY_TOKEN_SECRET' ) response = client.fetch_protected_resource( :uri => 'http://api.yelp.com/v2/search?location=new+york' ) # The Rack response format is used here status, headers, body = response p body 

According to the Yelp documentation , no OAuth parameters should be passed in the query string. The fact that the accepted answer resolved the problem indicates that there was probably an error in the oauth stone. This caused an error.

0
source

All Articles