npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-contacts-crud

v1.0.7

Published

Description ===========

Downloads

27

Readme

Description

Node.js wrapper for the Google Contacts API.

We can perfrom CRUD on Google Contacts

  • C : addContacts // single contacts at a time
  • R : getContacts // all or with filters
  • U : updateContacts // single contact update at a time
  • D : deteteContacts // mulitple delete with contact_ids and with filter single delete

Example Project.

Requirements

Installation

npm install google-contacts-crud

Examples

  • Set user's credentials.
var GoogleContacts = require("google-contacts-crud");



var googleContacts = new GoogleContacts(CLIENT_ID, CLIENT_SECRET);
var credentials    = {
  access_token : "youraccesstoken",
  expiry_date  : 3600,               
  refresh_token: "yourrefresh_token",
  token_type   : "Bearer"
};



googleContacts.setUserCredentials(credentials);

How to get CLIENT_ID and CLIENT_SECRET Steps

  • Create A Google Project.
  • Enable Google Contact Api (enable apis and services -> select Google Contact Api -> enable)
  • Create CLIENT_ID and CLIENT_SECRET (Create Credentials -> OAuth Client ID -> Web Application) * Enter App Name * Authorized JavaScript origins (your website name ) * Authorized redirect URIs (redirect URL, if you don't have, use 'https://developers.google.com/oauthplayground')

You get a initials access_token Steps

  • Open OAuth Background for Access Token
  • Enter CLIENT_ID and CLIENT_SECRET (Settings -> Use your own OAuth credentials)
  • Select https://www.google.com/m8/feeds/ (Select & authorize APIs -> Contacts V3)
  • Click on Authorize APIs
    • Google Login Form will Popup to authorize your scope
    • After authorization, it will redirect to your given redirect URL (https://developers.google.com/oauthplayground) with authorizing token
  • Click on Exchange authorization code for tokens Button to get your first access token

** Note Access Token will get expire after 3600 secs To Check your Access Token Status

Create Google Project OAuth Background for Access Token

  • Fetch all the contact's info such as 'name', 'email id', 'contact id',phoneNumber ,'contact type', shortmetadata and fullmetadata.

we can use fullmetadata to get additional information about a contact

For more info about query_params

// read

googleContacts.getContacts(function (error,contact) {
  console.log(error)
  console.log(contact)
});

// pass filter object
// filter based on {name,email,phoneNumber,other,contact_id} use any one
// filter

googleContacts.getContacts({"email":"[email protected]"},function (error,contact) {
  console.log(error)
  console.log(contact.length)
});
  • Add a new contact into user's Google contacts.

// create

var count=0;
  var createData = {
      name :'Ritesh Vishwakarma', // Default is ''
      display_name: 'Ritesh Raj Vishwakarma',  // Default is ''
      email       : '[email protected]',
      is_primary  : true,                     // Default is true
      contact_type: 'other',                  // Default is other.
      phoneNumber: '9876543210',                  // Default is other.
      headers     :{
          'GData-Version': '3.0',
          'User-Agent'   : 'SomeAgent'
      },
      extended_property: [                    // Optional
          {name: 'custom_key_2', value: 'custom_value_2'},
          {name: 'custom_key_2', value: 'custom_value_2'}
      ]
  };

googleContacts.addContact(createData, function (error,contact) {
  console.log(error)
  console.log(contact)
});

response contact
/*
{ contacts:
   [ { name: 'Ritesh Vishwakarma',
       email: '[email protected]',
       contact_type: 'other',
       id: '68eaba200b442ca7',
       phoneNumber: '9876543210',
       etag: '"Q3o4fjVSLit7I2A9XBZaGE0ORgA."',
       display_name: 'Ritesh Raj Vishwakarma',
       shortmetadata: [Object],
       fullmetadata: [Object] } ],
  next: null }
*/
  • Update a contact or a list of contacts from user's Google contacts list.
// single update with filter
  var updateData = {
      email       : '[email protected]',
      phoneNumber: '4321043210',        
      headers     :{
          'GData-Version': '3.0',
          'User-Agent'   : 'SomeAgent'
      }
  };
// pass filter object
// filter based on {name,email,phoneNumber,other,contact_id} use any one
// filter
// updates only first records
googleContacts.updateContacts({email:"[email protected]"},updateData,function (error, data) {
    console.log(error);
    console.log("Data " + JSON.stringify(data));
});

googleContacts.updateContacts({phoneNumber:"9876543210"},updateData,function (error, data) {
    console.log(error);
    console.log("Data " + JSON.stringify(data));
});
  • Delete a contact or a list of contacts from user's Google contacts list.
// single delete with filter
googleContacts.deleteContacts({phoneNumber:"4321043210"},function (error, data) {
    console.log("error",error);
    console.log("Data " + data);
});
var contact_ids=[
  '3e8b42898e977d',
  '305417c8c7e99a1',
  '6801c200cab6b86',
  '85924740a074822',
  '8e103600a8c2c97'
]
// multiple delete using contact_ids we will get id from getContacts
googleContacts.deleteContacts({contact_ids:contact_ids},function (error, data) {
    console.log("error",error);
    console.log("Data " + data);
});
  • To Refresh Google Access Token.
googleContacts.refreshToken(function(err,token){
  console.log("error",error);
  console.log("Data " + token);
})
response data

{ accessToken:"new access token",
  expiresIn: 3600,
  expiresAt: 1509790743244,
  idToken: undefined
}

If you find any error or you facing any difficulty please create an issue.