很是纠结了一段时间,下面直接上代码。
首先到这个网站上申请你的windows live 应用
https://manage.dev.live.com
注册帐号,申请API应用。
在rails里安装mislav_contacts 插件。
conf下新建import.yml文件
development: #开发环境下使用 windows_live: appid: #申请的ID 下面不在解释 secret: #申请的secret security_algorithm: wsignin1.0 return_url: #返回联系人列表的链接 policy_url: #首页 test: #测试环境下使用 windows_live: appid: secret: security_algorithm: wsignin1.0 return_url: policy_url: qa: #发布环境 windows_live: appid: secret: security_algorithm: wsignin1.0 return_url: policy_url: production:#正式运行环境 windows_live: appid: secret: security_algorithm: wsignin1.0 return_url: policy_url:
在 lib下新建 windows_live.rb
module Contacts class WindowsLive def initialize(config_file=CONFIG_FILE) confs = config_file.is_a?(Hash) ? config_file : YAML.load_file(config_file)['windows_live'] @wll = WindowsLiveLogin.new(confs['appid'], confs['secret'], confs['security_algorithm'], nil, confs['policy_url'], confs['return_url']) end end end
在controller下新建hotmailcontroller 文件
class HotmailController < ApplicationController layout "import" def authenticate #生成访问链接 redirect_to Import::Hotmail.authenticate end def authorize #返回处理 @contacts = Import::Hotmail.authorize(params).collect{|c| c.email}.sort flash[:notice] = "Hotmail" render :action=>"import" end end
路由内添加
resources :hotmail do collection do get 'authenticate' post 'authorize' get 'import' end end
在模块里创建import目录并创建hotmail.rb
module Import class Hotmail def self.authenticate wl = Contacts::WindowsLive.new(KEY_SECRET["windows_live"]) auth_url = wl.get_authentication_url end def self.authorize(params) wl = Contacts::WindowsLive.new(KEY_SECRET["windows_live"]) wl.contacts(params.merge("action" => "delauth").to_param) end end end
恩 这样就可以操作hotmail的联系人了,先记录下来。