我正在尝试使用2legged oauth向Web服务进行身份验证.我有下一个可用的Java示例,使用signpost库创建经过身份验证的URL:
String consumerKey = "KEY";
String consumerSecret = "SECRET";
DefaultOAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
consumer.setTokenWithSecret(consumerKey, consumerSecret);
return consumer.sign(targetUrl);
我正在尝试使用ruby的oauth重新创建它.我的代码现在看起来像这样:
consumer = OAuth::Consumer.new(@creds[:key], @creds[:secret],
:site => "URL",
:scheme => :query_string)
token = OAuth::Accesstoken.new(consumer)
token.get "METHOD"
并生成如下URL:
但是,即使我手动将oauth_token设置为key(如路标那样),也总是会出现Unauthorized错误.看起来随机数是无效的,但它们都是可用于oauth的有效库
谁能帮我?
提前致谢
解决方法:
我使用2腿式oauth遇到了同样的问题,我解决了:
consumer = OAuth::Consumer.new(key, secret, { :site => 'http://api.mysite.com' })
access_token = OAuth::Accesstoken.from_hash(consumer, :oauth_token => key, :oauth_token_secret => secret)
常见问题来自时间戳不同步
您的请求必须与服务器系统时钟同步,例如在Linkedin中必须在其系统时钟的5分钟之内.
希望能帮助到你
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。