teppeilog

ちょっとずつエンジンかかってきた

GoogleにClientLoginしてみる

leave a comment

GoogleのAPIを使用するためにClientLogin処理、C2DMを使ってみたいのでRubyで実装してみました。ClientLoginで取得するのは他のサービスを使うために必要なAuthのパラメータなので、それを取り出す。

require 'net/https'
require 'uri'

auth_hash = Hash.new

url = URI.parse("https://www.google.com/accounts/ClientLogin")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5

req = Net::HTTP::Post.new(url.path)

req.set_form_data({
:accountType => 'HOSTED_OR_GOOGLE',
:Email => 'hogehoge@gmail.com',
:Passwd => 'hogehoge',
:service => 'ac2dm',
:source => 'hogetest'
})

https.start do
  res = https.request(req)
  if res.code == "200"
    res.body.split("\n").each do |data|
      key,value = data.split("=")
      auth_hash[key] = value
    end
  end
end

print auth_hash['Auth'] # => 必要なAuth
このエントリーをはてなブックマークに追加
はてなブックマーク - GoogleにClientLoginしてみる
Share on Facebook

Written by teppei

2月 4th, 2011 at 2:30 pm