Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

vk

By: a guest on Feb 8th, 2011  |  syntax: Ruby  |  size: 1.62 KB  |  views: 281  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require "rubygems"
  2. require 'net/http'      
  3. require 'cgi'  
  4. require 'digest/md5'    
  5. require 'json/ext'  
  6. require 'httparty'  
  7. require "active_support/core_ext"
  8.  
  9. @app_id = '2157608'
  10. email = 'truschev@gmail.com'
  11. password = 'xxx'        
  12. app_rights = 16383
  13.  
  14. # Залогинивание и получение куки
  15. resp = Net::HTTP.post_form(URI.parse('http://vkontakte.ru/login.php'),
  16.                            {'m' => '1', 'email' => email, 'pass' => password})
  17. cookies = resp.response['set-cookie']
  18. remixsid = cookies.split('remixsid=')[1].split(';')[0].split(',')[0]  
  19. header = { "Cookie" => 'remixsid=' + remixsid }
  20.  
  21. conn = Net::HTTP.new('vkontakte.ru', 80)
  22.  
  23. # Парсим форму авторизации приложения
  24. resp = conn.get('http://vkontakte.ru/login.php?app=' + @app_id +
  25.                 '&layout=popup&type=browser&settings=32767', header)
  26. auth_hash = resp.body.split('var auth_hash = \'')[1].split('\';')[0]
  27.  
  28. # Авторизизуем приложение
  29. resp = conn.get('http://vkontakte.ru/login.php?act=a_auth&app=' + @app_id +
  30.                 '&hash=' + auth_hash + '&permanent=1', header)
  31. auth_json = resp.body
  32. p auth_json
  33.  
  34. auth = JSON.parse(auth_json)  
  35.  
  36. APP_ID = "2157608"
  37. private_key = "cad2kydg0I"
  38.  
  39. url = URI.parse("http://api.vkontakte.ru")
  40. http = Net::HTTP.new(url.host, url.port)  
  41. p auth
  42.  
  43. sig = Digest::MD5.hexdigest(auth["mid"].to_s + "api_id=#{APP_ID}format=JSONmethod=isAppUserv=3.0" + auth["secret"])
  44. resp, body = http.get("http://api.vkontakte.ru/api.php?api_id=#{APP_ID}&format=JSON&method=isAppUser&sid=#{auth["sid"]}&sig=#{sig}&v=3.0")
  45.  
  46. p JSON.parse(body)