Created
October 8, 2012 14:04
-
-
Save vexus2/3852700 to your computer and use it in GitHub Desktop.
[Ruby]ニコニコ動画APIを叩くとき用。事前にログインさせCookie値を取得する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ログインしてクッキー抽出 | |
def login(mail, pass) | |
host = 'secure.nicovideo.jp' | |
path = '/secure/login?site=niconico' | |
body = "mail=#{mail}&password=#{pass}" | |
https = Net::HTTP.new(host, 443) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
response = https.start { |https| | |
https.post(path, body) | |
} | |
cookie = '' | |
response['set-cookie'].split('; ').each do |st| | |
if idx=st.index('user_session_') | |
cookie = "user_session=#{st[idx..-1]}" | |
break | |
end | |
end | |
return cookie | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment