ruby on rails - Omnicontacts return empty array with @friends

357 Views Asked by At

I have some problem with Omnicontacts gem in RoR. It always return empty array when I import friends from Gmail. My config/omnicontacts.rb:

 require 'omnicontacts'

 Rails.application.middleware.use OmniContacts::Builder do
  importer :gmail, "775603091912-87u7d1bqgjrbsau8mtonb1pgp8nao386.apps.googleusercontent.com", 
                   "j3ymIJ0l3kEkGycqUzqkt-dJ"
 end

Code for OmniContactsController:

  class InvitesController < ApplicationController

  def contact_callback
    @contacts = request.env['omnicontacts.contacts']
    @user = request.env['omnicontacts.user']
    puts "List of contacts of #{user[:name]} obtained from #params[:importer]}:"
    @contacts.each do|contact|
      puts "Contact found: name => #{contact[:name]}, email => #{contact[:email]}"
    end
  end

  def index
    @contacts = request.env['omnicontacts.contacts']
    respond_to do |format|
      format.html
    end
  end

end

routes.rb

Rails.application.routes.draw do
  get "/invites/:provider/contact_callback" => "invites#index"
  get "/contacts/failure" => "invites#failure"
end

Help me please! Thanks!

1

There are 1 best solutions below

1
On

I believe that:

importer :facebook, "client_id", "client_secret", {
         :redirect_path => "/contacts/facebook/callback"
}

Should actually be

importer :facebook, "client_id", "client_secret"

Looking at the docs I don't see a need for the :redirect_path when dealing with facebook. Also it is not a good idea to publish your client_id and client_secret on public forums.