このスクリプトは「産業用」の使用を目的としておらず、認証方法は公式ではなく、変更される可能性があります。
require 'net/http' # ( ) app_id = '1234567' # ID , email = 'mail@example.com' password = 'qwerty' app_rights = 16383 # (16383 - ) # resp = Net::HTTP.post_form(URI.parse('http://vk.com/login.php'), {'m' => '1', 'email' => email, 'pass' => password}) cookies = resp.response['set-cookie'] remixsid = cookies.split('remixsid=')[1].split(';')[0].split(',')[0] # http://vk.com header = { "Cookie" => 'remixsid=' + remixsid } conn = Net::HTTP.new('vk.com', 80) # resp = conn.get('http://vk.com/login.php?app=' + app_id + '&layout=popup&type=browser&settings=32767', header) auth_hash = resp.body.split('var auth_hash = \'')[1].split('\';')[0] rights_hash = resp.body.split('var app_settings_hash = \'')[1].split('\';')[0] # req = '' mask = 1 14.times do if (app_rights & mask == 0) req += ('&app_settings_' + mask.to_s + '=0') else req += ('&app_settings_' + mask.to_s + '=1') end mask *= 2 end resp = conn.get('http://vk.com/apps.php?act=a_save_settings&addMember=1' + req + '&hash=' + rights_hash + '&id=' + app_id, header) # resp = conn.get('http://vk.com/login.php?act=a_auth&app=' + app_id + '&hash=' + auth_hash + '&permanent=1', header) auth_json = resp.body # API JSON puts auth_json # -
その結果、次の形式の回答が得られます。
{"mid":1000xxxxx,"sid":"xxxx6ed0xxxx2516xxxx49eacd0ec30f9961c01d30d15c3152e459xxxx", "secret":"335xxxxxxx","expire":0}
ある晩、個人的な目的で書かれたもので、キャプチャが必要なため、携帯電話に関連付けられていないアカウントの操作方法がわかりません。 また、起こりうるエラーを処理しません。
原則は明確であるため、必要に応じて変更できます。
APIの操作方法については、 vk.com / developers.phpで詳しく説明しています。
アプリケーションの権利についてはそこに書かれています。 承認フォームを受信すると、「settings = 32767」、つまり、すべての権利を明らかに取得できないように2 ^ n-1が示されました。 現在、16383は最大の権利に対応しており、将来変更される可能性があります。
PS 「単純な承認」はタイトルから削除されました。これは比較的単純であるが、些細なことと呼ぶのは難しいからです。