Blackbook gem can be used to fetch contacts from gmail, yahoo and hotmail address books. However I recently found out that it would throw up a ‘Must be authenticated to access contacts’ error everytime I tried to import gmail contacts. On digging deeper, I found out that google has changed the contents of its cookie and blackbook uses this cookie to make sure that the user is authenticated. To fix the issue, you just need to make a one line change in the function scrape_contacts in the file lib/blackbook/importer/gmail.rb.
Change
unless agent.cookies.find{|c| c.name == 'GAUSR' && c.value == "mail:#{options[:username]}"} raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." )
to
unless agent.cookies.find{|c| c.name == 'GAUSR' && (c.value =~ /mail.*:#{options[:username]}/)!=nil} raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." )
If you want to install the updated gem instead of making the change, you can find it in my blackbook fork. My fork also includes the myspace address book import
Hi Prateek
Thank you for sharing your work, this gem is indeed very useful! But right now, I have some trouble making it work:
- the blackbook 1.0.4 seems deprecated, it only works for Yahoo Mail
- with your blackbook update (I replaced my blackbook-1.0.4 folder with your blackbook folder – renamed blackbook-1.0.4 – in vendor/…), I ran into the same problem yesterday: only Yahoo is workin
Do I need to make any other changes to make it work or are Hotmail, Gmail, AOL scraping broken for you too?
Thanks for your help!
Link | October 8th, 2009 at 2:43 pm
Hi Jerry,
Can you please paste the exact error you are getting so I can look into it? Gmail and myspace is surely working for me. I think hotmail has some problem and I have not tried AOL.
Link | October 8th, 2009 at 4:13 pm
Nokogiri::CSS::SyntaxError in FooController#foo
unexpected ‘.’ after ‘.’
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/css/parser.rb:78:in `on_error’
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/css/parser.rb:70:in `xpath_for’
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/css.rb:21:in `xpath_for’
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/xml/node.rb:99:in `search’
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/xml/node.rb:97:in `map’
/Library/Ruby/Gems/1.8/gems/nokogiri-1.3.3/lib/nokogiri/xml/node.rb:97:in `search’
/Users/Jerry/Desktop/testapp/app/controllers/foo_controller.rb:148:in `foo’
That is the error I get trying to import Gmail contacts.
Yahoo scraping is working perfectly though… Thank you for your help.
Link | October 9th, 2009 at 1:51 am
Please make sure you have the following versions of these gems
hpricot (0.8.1)
mechanize (0.8.4)
nokogiri (1.2.3)
The blackbook gem does not work with the latest version of mechanize and nokogiri. I am not sure if hpricot is required.
Let me know if this helps
Link | October 9th, 2009 at 3:03 am
You’re RIGHT!!
Work only with mechanize (0.8.4) & nokogiri (1.2.3)…
THANK U SO MUCH FOR YOUR TIME
Link | October 10th, 2009 at 2:12 am
Are there any plans to get Blackbook to work with newer version of nokogiri? Version 1.4.0 to be more exact…
Link | November 29th, 2009 at 2:01 am
hpricot (0.8.1)
mechanize (0.8.4)
nokogiri (1.4.1)
WORKS FINE
Thanks !!
Link | December 18th, 2009 at 7:06 pm