Saturday, July 19, 2014

Import Contacts and Invite New Contacts By Email From Gmail Contacts API - Inspired By Linkedin,Twitter Mail Importer

Inviting by E-Mail is an excellent way for asking new users to try our sites,Which is actually sent by their friends or contacts in Address Book.As Like as LinkedIn,Twitter Gets your Email address especially Gmail and Access all your contacts and Matches with Their Email Database and shows their existing users to follow(connect) and invite New users to try their respective sites.It means enjoying the site with their friends(Especially Twitter does this).Even i too joined LinkedIn and Twitter because of Invitation mail from my friends in Gmail via Twitter,LinkedIn.


Import Contacts and Invite New Contacts By Email From Gmail Contacts API - Inspired By Linkedin,Twitter Importer











Reference :  
 |  

Script Structure :
  • index.php [ Main Html markup and other scripts ]
  • mail.php   [ Send Mail with Loop for Users ]
  • invite.js    [ javascript file handling JSON data append and processing Gmail Contacts API ] 
  • process.php [ Compare exisiting users and new users responding as JSON format to frontend ]

Scope : 

This is simple add-on Application for websites having Email users database.It is similar to Twitter,Linked Contact Importer where they get API access and fetch email from corresponding service and filter them accordingly as existing users and New users.and giving some options such as Follow or Connect and Inviting by Emails.

Javascript API for Gmail Contacts Import :

Gmail API Contacts let you to Read,Update,Create Contacts in Gmail.Core part of the Contacts API below Here.

Installation and Initialization:

check here how to get those keys 
 var clientId = 'Your Client ID here';
 var apiKey = 'Your api key here';
 var scopes = 'https://www.google.com/m8/feeds';

with this we are going to add Javascript plugin Jquery,Client.js from google



<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="https://apis.google.com/js/client.js"></script>


Javascript API to get Contact List as JSON data :

Check my Last post to Authorize a Google User and access their API - Click Here

$.get("https://www.google.com/m8/feeds/contacts/default/full?alt=json&access_token=" + authResult.access_token + "&max-results=700&v=3.0",
      function(response){
if(response.feed.entry.length > 0){
         //Handle Response
       console.log(response);
         var email= [];
console.log(response.feed.entry.length);
        for ( var i= 0 ; i < response.feed.entry.length ; i++)
    {  console.log(i);
          if(response.feed.entry[i].gd$phoneNumber)
           { continue; }
else{
      email[i]= response.feed.entry[i].gd$email[0].address;
      console.log(email[i]); }
 });

Posting the Javascript email array to proccess.php via ajax to filter new users and existing users.


$.post("process.php", { email: email },
    function(Result){
     //use the results to append to show the existing users to new users.
});


process.php


process.php just filter incoming list JSON contact email to existing email database.filter them as new users as object in json ,and existing users with their prof pic we are making another object in JSON.with header JSON/Application we are just encoding output via ajax to index.php

Download the Demo files try in Localhost ,I have added Mailing code via ajax too.If you can Find any error in Javascript (invite.js) just check the console and report error as comments/ or mail me [email protected]

14 comments:

anjani kumar said...

hey bro i am unable to send email to the contacts. when i am taking the table as a form then on submission it is generating a null array

s.shivasurya said...

may be error in ur array functions ! and check ur apache log for error paste the error here... and check twice u have email option to send via ur server!

anjani said...

i can send email to users for password or registration purpose.
But here the problem is
Select All
Step 1 of 2






 



and after submitting the output is array is null.
Pls tell me the process how to run loop to send invitation to the contacts if there is any other

anjani said...

u can check at www.circleddd.com/invite/index.php

s.shivasurya said...

what i have done is had submitted the email[checkedbox] via ajax jquery! pls add it

$('#invite').click(function(){
//submit the checked box buttons via ajax jquery and recieve with php POST });

Generally when u submit as checked box name of checkbix should be name="check[]" and submitted as array ! do for each loop and send mail! in mail.php

$list = $_POST['check'];

foreach ($list as $user){

$email = $user;

$message = "Welcome to i-visionblog.com | invite by email script! this is an test invite mail from localhost!";

$subject = "test mail - i-visionblog";

if (mail($email,$subject,$message)) {

echo "Thank you for sending email";

} else {

echo "Can't send email to $email";

}

}

?>





if any other technical prblem comment it! @anjani kumar

anjani said...

i am helpless bro. i tried everything under my scope. Pls tell me thecode what i have to write in invite.js and anything to write in index.php of ur package.

s.shivasurya said...

u have almost done ! i checked ur website populating fields well!
only thing u must submit the value of check box as an array to maIl.php , that too i hav generated !
so now use ajax jquery to submit the checked box value as an array to mail.php and receive it $_POST['check'] and run with for loop !
if u r php programmer u can do it easily!
still u need to full code ? @anjani kumar ! if so say me ! i will modify and mail u !

anjani said...

ya bro mail me the whole code. iam facing prblm in ajax submisson.
thanks fro helping me.

anjani said...

waiting

s.shivasurya said...

i will mail soon! connect with me on gmail!

ANJANI said...

OK
THANKS

anjani said...

hey bro you didnt send me the code. pls send it.
my email id is [email protected]

anjani said...

i tried this code but nthng is happening.

$('#invite').live("click",function() {

event.preventDefault();

$("#check").each(function () {

var data= new Object()

var access = new Array();

access.ChValue = $(this).attr("value");

if ($(this).attr("checked") == "checked") access.ChChecked = true;

data.push(access);

});

$.ajax({

type: 'POST',

url: '@Url.Content("~mail.php")',

data: $.json.encode(data),

dataType: 'json',

contentType: 'application/json; charset=utf-8'

});

});





pls tell me the error if there is any

anjani kumar said...

pls help yar.

Post a Comment

feel free to post your comments! Don't Spam here!