在Ruby on Rails中获取地址簿以获取Gmail,Yahoo,Hotmail,Twitter和Facebook联系人列表的问题

在搜索时遇到了Contacts插件。

但根据用法,自述文件中描述。 它需要用户名和密码才能获取联系人。 但这不是一个好方法。

对于Gmail或您的特定用途: Gmail通讯录 。

对于雅虎联系人,据我所知, 联系人似乎是使用的联系人 。 如果有人有更好的选择。 请提一下。

对于Twitter,我强烈推荐Twitter的gem。

对于Facebook,您已经对Facebook的gem进行了排序。 但是,我个人使用FB Graph 。

编辑:

嗯,我试着看一下doc。 没有提到的例子。 虽然确实提到:

有关使用GmailContacts的示例,请参阅sample / authsub.rb

哪个无处可寻。 也许给作者的快速电子邮件可能有帮助吗?

似乎联系人gem在网上得到很好的记录。 如果您能找到一种方法来满足您的项目要求。 然后,您可以将其用作其他电子邮件提供商的通用解决方案。

或者,联系人检索的另一种方式,我发现这可能是有用的。

用于Facebook登录的迷你FB插件 。 它还允许我获取用户联系人。 所以我可以将这个用于Facebook。 考拉是另一个吸引Facebook朋友的解决方案

FACEBOOK UPDATE

在这里我得到了Facebook的解决方案,但我只是告诉我邀请Facebook的朋友

 


Google Update

从谷歌开发者指南 ,我们有一个部分“检索所有联系人”,但在两者之间有一行写,即: –

注意:当前版本的Contacts API不支持检索其他用户的联系人。

  /* * Retrieve all contacts */ // Create the contacts service object var contactsService = new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0'); // The feed URI that is used for retrieving contacts var feedUri = 'http://www.google.com/m8/feeds/contacts/default/full'; var query = new google.gdata.contacts.ContactQuery(feedUri); // Set the maximum of the result set to be 50 query.setMaxResults(50); // callback method to be invoked when getContactFeed() returns data var callback = function(result) { // An array of contact entries var entries = result.feed.entry; // Iterate through the array of contact entries for (var i = 0; i < entries.length; i++) { var contactEntry = entries[i]; var emailAddresses = contactEntry.getEmailAddresses(); // Iterate through the array of emails belonging to a single contact entry for (var j = 0; j < emailAddresses.length; j++) { var emailAddress = emailAddresses[j].getAddress(); PRINT('email = ' + emailAddress); } } } // Error handler var handleError = function(error) { PRINT(error); } // Submit the request using the contacts service object contactsService.getContactFeed(query, callback, handleError); 

谷歌联系人的另一个服务器端解决方案:谷歌的解决方案:

从这里获取client_id和client_secret。 这是粗略的脚本,完美无缺。 根据您的需要对其进行修改。

  require 'net/http' require 'net/https' require 'uri' require 'rexml/document' class ImportController < ApplicationController def authenticate @title = "Google Authetication" client_id = "xxxxxxxxxxxxxx.apps.googleusercontent.com" google_root_url = "https://accounts.google.com/o/oauth2/auth?state=profile&redirect_uri="+googleauth_url+"&response_type=code&client_id="+client_id.to_s+"&approval_prompt=force&scope=https://www.google.com/m8/feeds/" redirect_to google_root_url end def authorise begin @title = "Google Authetication" token = params[:code] client_id = "xxxxxxxxxxxxxx.apps.googleusercontent.com" client_secret = "xxxxxxxxxxxxxx" uri = URI('https://accounts.google.com/o/oauth2/token') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data('code' => token, 'client_id' => client_id, 'client_secret' => client_secret, 'redirect_uri' => googleauth_url, 'grant_type' => 'authorization_code') request.content_type = 'application/x-www-form-urlencoded' response = http.request(request) response.code access_keys = ActiveSupport::JSON.decode(response.body) uri = URI.parse("https://www.google.com/m8/feeds/contacts/default/full?oauth_token="+access_keys['access_token'].to_s+"&max-results=50000&alt=json") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) contacts = ActiveSupport::JSON.decode(response.body) contacts['feed']['entry'].each_with_index do |contact,index| name = contact['title']['$t'] contact['gd$email'].to_a.each do |email| email_address = email['address'] Invite.create(:full_name => name, :email => email_address, :invite_source => "Gmail", :user_id => current_user.id) # for testing im pushing it into database.. end end rescue Exception => ex ex.message end redirect_to root_path , :notice => "Invite or follow your Google contacts." end end 

设置截图。

在此处输入图像描述

对于Gmail而不是使用任何gem,你应该使用示例代码,这不值得gem。

请在此处查看我的示例代码 – https://gist.github.com/742461

实际上这里有一篇博客文章 – http://rtdptech.com/2010/12/importing-gmail-contacts-list-to-rails-application/但似乎目前正面临重定向问题。

您需要通过联接表跟踪哪些用户邀请了谁。 这是FB.ui JS w / callback让你入门:

 FB.ui({ method: 'apprequests', title: t, message: m }, function(response) { if (response) { $.ajax({ type: 'POST', url: "/invitation_requests/create", data: { "requests[]" : response.request_ids }, timeout: 12500, async : false, // This fixes an issue w/ IE complete: function() { $.cookie( "latest_request_ids", response.request_ids.length ); window.location = "/users" } }); } });