对请求令牌的 OAuth 调用会产生 404 错误

发布于 2024-11-30 01:01:29 字数 1051 浏览 0 评论 0原文

我在让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

反目相谮 2024-12-07 01:01:29

我也有同样的问题。 request_token_url方法返回正确的url,但我通过wireshark观察真实请求的url,并且有www.flickr.com/oauth/request_token..所以它需要将/services路径从:site选项移动到paths选项。

这段代码现在对我有用:

    consumer = OAuth::Consumer.new(key, secret, 
            :site               => "http://www.flickr.com", 
            :request_token_path => '/services/oauth/request_token', 
            :authorize_path     => '/services/oauth/authorize',
            :access_token_path  => '/services/oauth/access_token')
    request_token = consumer.get_request_token

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:

    consumer = OAuth::Consumer.new(key, secret, 
            :site               => "http://www.flickr.com", 
            :request_token_path => '/services/oauth/request_token', 
            :authorize_path     => '/services/oauth/authorize',
            :access_token_path  => '/services/oauth/access_token')
    request_token = consumer.get_request_token
‘画卷フ 2024-12-07 01:01:29

我遇到了同样的问题,但我的回调网址是“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文