验证Google帐号和密码的Ruby代码

我在Rubyforge上看到的,它的0.1版本将第一行的代码注释掉了,代码是不能运行的,我将第一行的注释去掉了,代码可以工作了,enjoy it!

require 'net/https'

def GoogleLogin(username, password)
url = URI.parse('https://www.google.com/accounts/ClientLogin')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
res = http.start do |http|
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'Email'=>username, 'Passwd'=>password, 'service'=>'xapi', 'source'=>'rails-plugins'},'&')
http.request(req)
end
case res
when Net::HTTPSuccess #, Net::HTTPRedirection
true
else
false
end
end

#测试
if GoogleLogin('boy.365@126.com ','mypassword')
puts "suc"
else
puts "failed"
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值