Mendeley有一個很棒的API(事實上他們已經提出了一個使用他們的API的比賽,但這個問題並不是特定的),它使用OAuth。Mendeley自定義OAuth策略
我想寫一個戰略,讓Mendeley認證,和時遇到了不少麻煩這樣做..
我去/ auth /中mendeley,它重定向我Mendeley.com,我驗證,然後將其重定向我什麼也沒有它的網頁,但這個
{「錯誤」:「消費者鍵未找到」}
他們提到這是一個3腳的OAuth,是東西那需要比OAuth通常所做的額外步驟?
以下是我有:
# /config/initializers/omniauth.rb
module OmniAuth
module Strategies
# tell omniauth to load the strategy
autoload :Mendeley, 'lib/mendeley'
end
end
# gather oauth credentials from the yml file
OAUTH = YAML.load_file(File.join(Rails.root, "config", "oauth.yml"))
# load all the possible oauth strategies
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider OmniAuth::Strategies::Mendeley, OAUTH['mendeley']['consumer_key'], OAUTH['mendeley']['consumer_secret']
end
# lib/mendeley.rb
require 'omniauth/oauth'
require 'multi_json'
module OmniAuth
module Strategies
# Omniauth strategy for using oauth2 and mendeley.com
class Mendeley < OAuth2
def initialize(app, consumer_key = nil, consumer_secret = nil, &block)
client_options = {
:site => 'http://api.mendeley.com'
}
super(app, :mendeley, consumer_key, consumer_secret, client_options, &block)
end
end
end
end
這不是一個直接的答案,但一些[dev的郵件列表]上(http://groups.google.com/group/ mendeley-open-api-developers /)發現將HTTP方法從POST更改爲GET可解決問題。 – 2011-05-12 01:37:00
你是否指定重定向網址? – netbrain 2011-05-30 13:17:50
哪裏?在我的代碼中,還是在Mendeley應用程序中? – Rabbott 2011-05-30 16:40:46