Class: FacebookToken::Dev

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_token.rb

Class Method Summary collapse

Class Method Details

.fetch(opt = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/facebook_token.rb', line 8

def self.fetch(opt = {})
  agent = Mechanize.new
  agent.follow_meta_refresh = true
  agent.get('https://www.facebook.com')
  form = agent.page.form_with(id: 'login_form')
  form.email = opt[:email] || opt['email']
  form.pass  = opt[:password] || opt['password']
  agent.submit(form)
  agent.get("https://developers.facebook.com/tools/accesstoken/?app_id=#{opt[:app_id] || opt['app_id']}")
  begin
    agent.page.search("table")[0].search("code")[0].text
  rescue Exception => e
    raise InvlidAccountException, 'Invlid acount or facebook app_id'
  end
end