Git Product home page Git Product logo

cordova-plugin-googleplus's Introduction

Google+ Cordova / PhoneGap Plugin

by Eddy Verbruggen

0. Index

  1. Description
  2. Screenshots
  3. Installation (CLI / Plugman)
  4. Google+ API setup
  5. Usage
  6. Changelog
  7. License

1. Description

This plugin allows you to log on with your Google account on iOS and Android. You will not only get the email address of the user, but also stuff like their full name and gender.

2. Screenshots

Android

   

iOS

   

3. Installation (PhoneGap CLI / Cordova CLI)

This plugin is compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here's how it works with the CLI (backup your project first!):

$ phonegap local plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git

or, my personal preference

$ cordova plugin add https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git
$ cordova prepare

GooglePlus.js is brought in automatically. There is no need to change or add anything in your html.

4. Google+ API setup

To communicate with Google+ you need to do some tedious setup, sorry.

iOS

To get your iOS API key, follow Step 1 of this guide

Android

To configure Android, follow Step 1 of this guide

5. Usage

Check the demo app to get you going quickly, or hurt yourself and follow these steps.

Note that none of these methods should be called before deviceready has fired.

Login

window.plugins.googleplus.login(
    {
      'iOSApiKey': '1234567890-abcdefghijklm74bfw.apps.googleusercontent.com'
    },
    function (obj) {
      alert(JSON.stringify(obj)); // do something useful instead of alerting
    },
    function (msg) {
      alert('error: ' + msg);
    }
);

Note that if you're only targeting iOS you can pass {} for the first argument.

The success callback (second argument) gets a JSON object with the following contents, with example data of my Google+ account:

 obj.email        // '[email protected]'
 obj.displayName  // 'Eddy Verbruggen'
 obj.gender       // 'male' (other options are 'female' and 'unknown'
 obj.imageUrl     // 'http://link-to-my-profilepic.google.com'
 obj.givenName    // 'Eddy'
 obj.middleName   // null (or undefined, depending on the platform)
 obj.familyName   // 'Verbruggen'

Try silent login

When the user comes back to your app and you're not sure if he needs to log in, you can call trySilentLogin to try loggin him in.

If it succeeds you will get the same object as the login function gets, but if it fails it will not show the authentication dialog to the user.

The code is exactly the same a login, except for the function name.

window.plugins.googleplus.trySilentLogin(
    {
      'iOSApiKey': '1234567890-abcdefghijklm74bfw.apps.googleusercontent.com'
    },
    function (obj) {
      alert(JSON.stringify(obj)); // do something useful instead of alerting
    },
    function (msg) {
      alert('error: ' + msg);
    }
);

logout

This will clear the OAuth2 token.

window.plugins.googleplus.logout(
    function (msg) {
      alert(msg); // do something useful instead of alerting
    }
);

disconnect

This will clear the OAuth2 token and forget which account was used to login. On Android this will always force the user to authenticate the app again, on iOS using logout seems to do the job already. Need to investigate this a bit more..

window.plugins.googleplus.disconnect(
    function (msg) {
      alert(msg); // do something useful instead of alerting
    }
);

6. CHANGELOG

1.0.0: initial version supporting iOS and Android

7. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cordova-plugin-googleplus's People

Contributors

eddyverbruggen avatar

Watchers

James Cloos avatar Jose Ignacio Decima avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.