提取地址簿以获取Ruby on Rails中的Gmail,Yahoo,Hotmail,Twitter和Facebook联系人列表中的问题 [英] Issues in fetching address book to fetch Gmail, Yahoo, Hotmail, Twitter and Facebook contact list in Ruby on Rails

查看:86
本文介绍了提取地址簿以获取Ruby on Rails中的Gmail,Yahoo,Hotmail,Twitter和Facebook联系人列表中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索时浏览联系人插件。



但按照使用情况,在自述文件中描述。它需要用户名和密码来获取联系人。但这不是一个好方法。

解决方案

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



FACEBOOK UPDATE



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

 < div id =facebook_invitesclass =conclusionstyle =width:750px; text-align:center> 
< a id =wall_posthref =#style =font-size:2em;>贴在墙上< / a>< br />
< a id =invite_friendshref =#style =font-size:1.5em;>邀请您的好友< / a>
< / div>
< div id =fb-root>< / div>


< script type =text / javascriptsrc =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 /',
描述:'abc is cool。',
name:'abc.com'});
});
$ b $('#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更新



来自 google开发者指南,我们有一个检索所有联系人部分,但是在两者之间有一行书面即: -

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

检索所有联系人
* /

//创建联系人服务对象
var contactsService =
new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0');

//用于检索联系人的订阅源URI
var feedUri ='http://www.google.com/m8/feeds/contacts/default/full';
var query = new google.gdata.contacts.ContactQuery(feedUri);

//设置结果集的最大值为50
query.setMaxResults(50);

//当getContactFeed()返回数据时调用回调方法
var callback = function(result){

//一组联系人条目
var entries = result.feed.entry;

//遍历数组联系条目
for(var i = 0; i< entries.length; i ++){
var contactEntry = entries [i];

var emailAddresses = contactEntry.getEmailAddresses();

//遍历属于单个联系人条目的电子邮件数组
for(var j = 0; j< emailAddresses.length; j ++){
var emailAddress = emailAddresses [j]的.getAddress();
PRINT('email ='+ emailAddress);



$ //错误处理程序
var handleError = function(error){
PRINT(error);
}

//使用contacts服务对象提交请求
contactsService.getContactFeed(query,callback,handleError);

Google联系人的另一个侧面解决方案:
Google解决方案: strong>



获取您的client_id和client_secret这里。这是粗略的脚本,它工作得很好。根据您的需求修改它。

 要求'net / http'
要求'net / https'
要求'uri'
需要'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
结束

def授权
开始
@title =Google认证
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 :: Pos t.new(uri.request_uri)

request.set_form_data('code'=>令牌,'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']
联系['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)#用于测试im推入数据库..
结束
$ b $结束
rescue例外=> ex
ex.message
end
redirect_to root_path,:notice => 邀请或关注您的Google联系人。


结束

结束

设置的屏幕截图。




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.

解决方案

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 UPDATE

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 Update

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

Note: Retrieving another user's contacts is not supported by the current version of the 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);

Another sever side solution for google contacts: Solution for google:

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

Screenshot for settings.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆