perl - Using Mechanize with Google's 2FA -


i'm trying retrieve data (google) web service using mechanize.

if user not have 2fa (two factor authentication) code works:

#!/usr/bin/perl  $email = 'xxxxx'; $pass = 'xxxxx';  use www::mechanize;  $time1 = (time - 24 * 60 * 60) * 1000; $time2 = (time + 24 * 60 * 60) * 1000;  $mech = www::mechanize->new(); $mech->get("https://maps.google.com/locationhistory/b/0/kml?starttime=$time1&endtime=$time2"); $mech->submit_form(fields => { 'email' => $email, 'passwd' => $pass, }, ); $mech->content =~ m!.*<gx:coord>(.*?)</gx:coord>!s; $coord = $1; my($lng, $lat) = ($coord =~ /^([-+]?[\d\.]+)[ ,]+([-+]?[\d\.]+)/); 

if user has 2fa switched on, after submitting password page asks 2fa code. have token generates code - i'm not sure how submit it.

(nb i've tried using app specific passwords - don't work sort of access.)

  1. how can submit 2fa code on second page?
  2. is there way can store cookie don't have use 2fa token each time?


Comments