Last Updated: November 22, 2018
· Khor

Use OAuth to Import Gmail Contacts In 15 Lines


We found that the simplest way to import contacts from Gmail is to use OAuth. Here is a short Javascript code snippet to do it in less than 10 lines using

Code Snippet

You can test importing your Gmail contacts using the code snippet below. Click on the social button to log into your Gmail account, and it will get the import the contacts from that Gmail account.

Code Explanation


<a id="drive-button" class="btn btn-block btn-social btn-vimeo">
  <i class="fa"></i> Contact list




$('#drive-button').on('click', function() {
  // Initialize with your app public key
  // Use popup for oauth
  OAuth.popup('google_contact').then(provider => {
    console.log('provider:', provider);

    provider.get('/m8/feeds/contacts/default/full').then(data => {
      console.log('Contacts:', data);

External Requirements

This Javascript code has external requirements:

Step-by-step Guide

Here is a summary of the steps to create this social button to get file list from Dropbox on a user's behalf using OAuth2.

  1. Create a Gmail account, if you do not have one
  2. Create an app on Google application using this simple step-by-step guide
  3. Copy your Google app client id and client secret
  4. Signup for account
  5. Link your Google app with by pasting your Google app client id and client secret into
  6. Copy the OAuth javascript snippet ( on to your web page


Use OAuth to import contacts from Gmail: