我可以使用rails中的OAuth gem成功地从谷歌获取联系人。我的gmail配置是:
:google=>{
:key=>"***",
:secret=>"***",
:expose => true,
:scope=>"https://www.google.com/m8/feeds/"
}
现在我想联系雅虎和热邮件。如何获得该联系人我在oauth_consumer.rb文件中给出了以下配置
:yahoo=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**",
:scope=>"https://me.yahoo.com"
}
:hotmail=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**"
}
当我试图像在谷歌中一样做同样的事情时,它会给出错误like undefined method
downstase'for nil:NilClass`
我也尝试过联系人gem,但未能加载联系人。
请尝试使用OmniContactshttps://github.com/Diego81/omnicontacts这对你有很大帮助。
-
在您的gemfile 中
gem "omnicontacts"
-
创建配置/初始化程序/omnicontacts.rb
require "omnicontacts" Rails.application.middleware.use OmniContacts::Builder do importer :gmail, "client_id", "client_secret", {:redirect_path => "/oauth2callback", :ssl_ca_file => "/etc/ssl/certs/curl-ca-bundle.crt"} importer :yahoo, "consumer_id", "consumer_secret", {:callback_path => '/callback'} importer :hotmail, "client_id", "client_secret" importer :facebook, "client_id", "client_secret" end
-
创建一个应用程序到雅虎https://developer.apps.yahoo.com/projects
这将要求验证您的域。所以,只需将您的域
localhost:3000
更改为local.appname.com:3000
,或者更喜欢您的实时服务器。。。(更改本地主机--sudo gedit/etc/hosts) -
在您的控制器中
@contacts = request.env['omnicontacts.contacts'] @user = request.env['omnicontacts.user'] puts "List of contacts of #{user[:name]} obtained from #{params[:importer]}:" @contacts.each do |contact| puts "Contact found: name => #{contact[:name]}, email => #{contact[:email]}" end