对请求令牌的 OAuth 调用会产生 404 错误
我在让 OAuth gem 为 Flickr API 正常工作方面遇到了非常困难的事情。我正在尝试使用此代码生成请求令牌:
user_oauth = OAuth::Consumer.new(consumer_key, consumer_secret, :site => "https://secure.flickr.com/services")
request_token = user_oauth.get_request_token(:oauth_callback => callback_url)
每当我运行此代码时,它都会在调用 .get_request_token 时抛出异常“OAuth::Unauthorized (404 Not Found)”。
我的终点来自: http://www.flickr.com/services/ api/misc.overview.html
我的 OAuth gem 使用默认的 request_token 路径,该路径应该与 Flickr 一起使用,根据:http://www.flickr.com/services/api/auth.oauth.html #request_token 我还尝试使用此链接使用的端点 (http://www.flickr.com/services)
当我在 OAuth::Consumer 上调用 .request_token_url 时对象,它返回“https://secure.flickr.com/services/oauth/request_token”,我可以在浏览器中访问它。考虑到 flickr API 可能只适用于 GET 请求,我将 OAuth 方法更改为 GET,但仍然不起作用。
我之前在不同的 API 上使用过完全相同的代码并且它有效,所以我不太确定此时该怎么做。任何帮助将不胜感激!
I am having an incredibly difficult time getting the OAuth gem working correctly for the Flickr API. I'm trying to generate a request token using this code:
user_oauth = OAuth::Consumer.new(consumer_key, consumer_secret, :site => "https://secure.flickr.com/services")
request_token = user_oauth.get_request_token(:oauth_callback => callback_url)
Whenever I run this code it throws an exception "OAuth::Unauthorized (404 Not Found)" on the call to .get_request_token.
I got my end point from: http://www.flickr.com/services/api/misc.overview.html
My OAuth gem is using the default request_token path, which should work with Flickr according to: http://www.flickr.com/services/api/auth.oauth.html#request_token I also tried using the endpoint that this link uses (http://www.flickr.com/services)
When I call .request_token_url on my OAuth::Consumer object, it returns "https://secure.flickr.com/services/oauth/request_token", which I can access in my browser. Thinking that the flickr API might only work with GET requests, I changed the OAuth method to GET and it still didn't work.
I've used this exact same code on different APIs before and it worked, so I'm not really sure what to do at this point. Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有同样的问题。 request_token_url方法返回正确的url,但我通过wireshark观察真实请求的url,并且有www.flickr.com/oauth/request_token..所以它需要将/services路径从:site选项移动到paths选项。
这段代码现在对我有用:
I had the same problem. Request_token_url method returns right url, but I watch on true requested url by wireshark and there was www.flickr.com/oauth/request_token.. So it needs to move /services path from :site option into paths options.
This code works for me, now:
我遇到了同样的问题,但我的回调网址是“oob”,他们说如果您无法访问浏览器,请使用它。无论如何,我把引号从 oob 中删除了,现在它可以工作了。
I was having the same issue, but my callback url was "oob" which they say to use if you don't have access to a browser. Anyway I took the quotes off the oob and it works now.