Git Product home page Git Product logo

angular-google-gapi's Introduction

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.

Requirements

Installation

Add library

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

bower install angular-google-gapi

or you may download the latest release

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

Add dependency

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

Configuration

without Google Auth

add run in root module

app.run(['GApi',
    function(GApi) {
        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/)
    }
]);

with Google Auth

add run in root module

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

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

	GApi.load('myApiName','v1',BASE);

        GAuth.setClient(CLIENT);
        
        GAuth.checkAuth().then(
            function () {
                $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
            }
        );
        
    }

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(){
        	$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.gapi.user)
    }
]);
<h1>{{gapi.user.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)

angular-google-gapi's People

Contributors

alexandrebrasil avatar maximepvrt avatar

Watchers

 avatar  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.