Question

this week I'm having problems logging in LinkedIn using ruby mechanize. My code is as follows:

agent = WWW::Mechanize.new
home_page = agent.get('http://www.linkedin.com')
sign_in_link = home_page.links.find{|link| link.text == "Sign In"}
login_form = sign_in_link.click.form('login')
# with email and password variables properly set
login_form.set_fields(:session_key => email, :session_password => password)
return_page = agent.submit(login_form, login_form.buttons.first)

Last week it worked OK but now it's failing, the return_page variable shows a 'redirecting...' message but when I use the same agent to fetch 'http://www.linkedin.com/home', it's as if I've never signed in (although cookies show otherwise). Can someone try to duplicate this error?

Thanks in advance.

Was it helpful?

Solution

In our case we succeded using curl inside our controller, here is a snippet of what we do, we do a curl call to log in and store the cookies in a file named j and then use it for every subsequent request, hacky but works in the meantime.

 curl_login = `curl --cookie-jar j -so/dev/null -Fsession_login= -Fsession_rikey= -Fsession_key=#{contact} -Fsession_password=#{password} https://www.linkedin.com/secure/login?trk=hb_signin`

 curl_for_profile = `curl --cookie j "#{profile_url}"`

Let me know if you have any question

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top