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

本文介绍了在 Ruby on Rails 中获取地址簿以获取 Gmail、Yahoo、Hotmail、Twitter 和 Facebook 联系人列表的问题的处理方法,对大家解决问题具有一定的参考价值

问题描述

在搜索时遇到了 Contacts 插件.

Came across the Contacts plugin while searching.

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

But as per the usage, described in the readme file. It requires username and password to fetch contacts. But that's not a good approach.

推荐答案

迷你FB插件 用于 Facebook 登录.它还允许我获取用户联系人.所以我可以将这个用于 Facebook.Koala 是另一种获取 facebook 好友的解决方案

Mini FB plugin for Facebook login. It also allows me to fetch users contacts. So I can use this one for Facebook. Koala is another solution for fetching facebook friends

脸书更新

我在这里找到了 facebook 的解决方案,但它只是告诉我邀请朋友使用 facebook

Here i got the solution for facebook, but i it just show me invite friends for facebook

    <div id="facebook_invites" class="conclusion" style="width: 750px; text-align: center">
      <a id="wall_post" href="#" style="font-size: 2em;">Post on your Wall</a><br/>
      <a id="invite_friends" href="#" style="font-size: 1.5em;">Invite your Friends</a>
      </div>
        <div id="fb-root"></div>


      <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
        <script type="text/javascript">
          $('#wall_post').click(function() {
            FB.init({
              appId:'app_id', cookie:true,
              status:true, xfbml:true
            });

            FB.ui({ method: 'feed',
              link: 'http://localhost:3000/',
              picture: 'http://localhost:3000/',
              description: 'abc is cool.',
              name: 'abc.com'});
          });

          $('#invite_friends').click(function() {
            FB.init({
              appId:'app_id', cookie:true,
              status:true, xfbml:true
            });

            FB.ui({ method: 'apprequests',
              message: 'abc is cool.'});
          });
        </script>

<小时><小时>

谷歌更新

来自 google 开发者指南,我们有一个部分检索所有联系人",但中间有一行写成ie:-

From google developers guide, we have a section "Retrieving all contacts", But in between there is a line written ie:-

注意:当前版本的 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);

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

此处获取您的 client_id 和 client_secret.这是一个粗略的脚本,效果很好.根据您的需要对其进行修改.

Get your client_id and client_secret from here. This is rough script, which works perfectly fine. Modified it as per your needs.

    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 i m 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

设置屏幕截图.

这篇关于在 Ruby on Rails 中获取地址簿以获取 Gmail、Yahoo、Hotmail、Twitter 和 Facebook 联系人列表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1173

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1071

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this-&gt;id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:808

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this-&gt;id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:900

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:930

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:877

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:865

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:834

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1734

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1309