You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

angular-google-gapi

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-google-gapi

An AngularJS module for use all Google Apis and your Google Cloud Endpoints (Google App Engine) with OAuth. This module use Google APIs Client Library for JavaScript, available for all GApis.

1.0.0-beta.1
Source
npmnpm
Version published
Weekly downloads
19
26.67%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Google GApi

An AngularJS module for use all Google Apis and your Google Cloud Endpoints (Google App Engine) with OAuth. This module use Google APIs Client Library for JavaScript, available for all GApis.

Example

An example is executed here : http://maximepvrt.github.io/angular-google-gapi/

The code is available here : https://github.com/maximepvrt/angular-google-gapi/tree/gh-pages

Requirements

  • Angular.js

Installation

Add library

This module is available as bower package, install it with this command:

bower install angular-google-gapi

and it's available too as npm package, install it with this command:

npm install angular-google-gapi

or you may download the latest release

<script type="text/javascript" src="/angular-google-gapi/dist/angular-google-gapi.min.js"></script>

Add dependency

var app = angular.module('myModule', ['angular-google-gapi']);

Configuration

without Google Auth

add run in root module

app.run(['GApi', 'GAuth',
    function(GApi, GAuth) {
        var BASE = 'https://myGoogleAppEngine.appspot.com/_ah/api';
        GApi.load('myApiName','v1',BASE).then(function(resp) {
            console.log('api: ' + resp.api + ', version: ' + resp.version + ' loaded');
        }, function(resp) {
            console.log('an error occured during loading api: ' + resp.api + ', resp.version: ' + version);
        });
    }
]);

with Google Auth

add run in root module

app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope',
    function(GAuth, GApi, Gdata, $state, $rootScope) {

        $rootScope.gdata = GData;

        var CLIENT = 'yourGoogleAuthAPIKey';
        var BASE = 'https://myGoogleAppEngine.appspot.com/_ah/api';

	    GApi.load('myApiName','v1',BASE);
	    GApi.load('calendar','v3'); // for google api (https://developers.google.com/apis-explorer/)

        GAuth.setClient(CLIENT);
        GAuth.setScope("https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly"); // default scope is only https://www.googleapis.com/auth/userinfo.email

        GAuth.checkAuth().then(
            function (user) {
                console.log(user.name + 'is login')
                $state.go('webapp.home'); // an example of action if it's possible to
                			  // authenticate user at startup of the application
            },
            function() {
		        $state.go('login');       // an example of action if it's impossible to
					  // authenticate user at startup of the application
            }
        );

    }
]);

GApi.load Error handling

+```javascript +GApi.load('myApiName','v1',BASE)

  • .catch(function(api, version) {
  •    console.log('an error occured during loading api: ' + api + ', version: ' + version);
    
  • }); +```

Use

Execute your api without params

app.controller('myController', ['$scope', 'GApi',
    function myController($scope, GApi) {
      	GApi.execute('youApi', 'you.api.method.name').then( function(resp) {
	    $scope.value = resp;
	}, function() {
		console.log("error :(");
	});
    }
]);

Execute your api with params

app.controller('myController', ['$scope', 'GApi',
    function myController($scope, GApi) {
	GApi.execute('youApi', 'you.api.method.name', {parm1: value}).then( function(resp) {
	    $scope.value = resp;
	}, function() {
		console.log("error :(");
	});
    }
]);

Execute your api without params with Google Auth

app.controller('myController', ['$scope', 'GApi',
    function myController($scope, GApi) {
      	GApi.executeAuth('youApi', 'you.api.method.name').then( function(resp) {
	    $scope.value = resp;
	}, function() {
		console.log("error :(");
	});
    }
]);

Execute your api with params with Google Auth

app.controller('myController', ['$scope', 'GApi',
    function myController($scope, GApi) {
	GApi.executeAuth('youApi', 'you.api.method.name', {parm1: value}).then( function(resp) {
	    $scope.value = resp;
	}, function() {
		console.log("error :(");
	});
    }
]);

Signup with google

app.controller('myController', ['$scope', 'GAuth', '$state',
    function myController($scope, GAuth, $state) {

	$scope.doSingup = function() {
      	    GAuth.login().then(function(user){
                console.log(user.name + 'is login')
        	    $state.go('webapp.home'); // action after the user have validated that
        				  // your application can access their Google account.
            }, function() {
            	console.log('login fail');
            });
      };
    }
]);

Get user info

Get user info after login is very simple.

app.controller('myController', ['$rootScope',
    function myController($rootScope) {
        console.log($rootScope.gdata.getUser().name)
    }
]);
<h1>{{gdata.getUser().name}}</h1>

User object :

  • user.email
  • user.picture (url)
  • user.id (Google id)
  • user.name (Google account name or email if don't exist)
  • user.link (link to Google+ page)

Development

Gulp is used to minify angular-google-gapi.js (using Uglify). Execute 'npm install' (requires Node and NPM) to install the required packages.

Run "gulp" to generate a minified version (angular-google-gapi.min.js). Note that this requires gulp to be installed globally (via 'npm install -g gulp').

Keywords

google apis

FAQs

Package last updated on 24 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts