Sep
17
2009

Authentication error while fetching gmail contacts using blackbook

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

posted in Uncategorized by prateek

Follow comments via the RSS Feed | Leave a comment | Trackback URL

7 Comments to "Authentication error while fetching gmail contacts using blackbook"

  1. Jerry wrote:

    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!

  2. prateek wrote:

    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.

  3. Jerry wrote:

    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.

  4. prateek wrote:

    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

  5. Jerry wrote:

    You’re RIGHT!!

    Work only with mechanize (0.8.4) & nokogiri (1.2.3)…
    THANK U SO MUCH FOR YOUR TIME :-)

  6. Blim wrote:

    Are there any plans to get Blackbook to work with newer version of nokogiri? Version 1.4.0 to be more exact…

  7. Julien wrote:

    hpricot (0.8.1)
    mechanize (0.8.4)
    nokogiri (1.4.1)

    WORKS FINE
    Thanks !!

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by openark.org