使用 Ruby + OAuth 访问 Yelp API
我刚刚开始使用 OAuth,我尝试制作一个小型客户端来连接到一些 Web 服务...我尝试了 twitter,它的工作方式就像一个魅力,但是,我也尝试访问 Yelp V2 API(遵循他们的 Python 示例),但是我总是回复: HTTP 400错误请求
缺少参数:oauth_consumer_key
这是我的代码:
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
无论如何,该代码与twitter API一起使用没有任何问题(我实际上遵循了twitter的示例代码)
提前干杯并感谢, 泽
I just getting started with OAuth, and I tried to make a small client to connect to some webservices... I tried twitter and it worked like a charm, however, I also tried to access Yelp V2 API (following their Python example) but I always get back as an answers:
HTTP 400 Bad Request
Missing parameter: oauth_consumer_key
Here's 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 to say, that code works with twitter API without any problem (I actually followed twitter's example code)
Cheers and thanks in advance,
Ze
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 :query_string 而不是 :header 一切都会起作用(至少对我来说)。
Use :query_string instead of :header and everything will work (at least for me).
相同的代码,使用 Signet:
按照 Yelp 文档 中,OAuth 参数不必必须在查询字符串中传递。事实上,接受的答案解决了这个问题,这向我表明,
oauth
gem 中可能存在导致此问题的错误。Same code, using Signet:
As per the Yelp documentation, the OAuth parameters do not have to be passed in the query string. The fact that the accepted answer resolved the issue indicates to me that there's probably a bug in the
oauth
gem causing this.