diff --git a/README.md b/README.md index 4170beb..66cb6f2 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ Be sure to include "gapi" as a dependency in your main app module. After you register your app in the [Google APIs Console](https://code.google.com/apis/console), configure ngGAPI with credentials and whatever scopes you need for your app. +###with OAuth 2.0 angular.module('myApp') .value('GoogleApp', { - apiKey: 'YOUR_API_KEY', clientId: 'YOUR_CLIENT_ID', scopes: [ // whatever scopes you need for your app, for example: @@ -44,7 +44,13 @@ After you register your app in the [Google APIs Console](https://code.google.com 'https://www.googleapis.com/auth/userinfo.profile' // ... ] - }) + }); + +### with API keys + angular.module('myApp') + .value('GoogleApp', { + apiKey: 'YOUR_API_KEY' + }); To use a specific service, inject it into your controllers by name. All GAPI methods return a promise. diff --git a/gapi.js b/gapi.js index 3170b9c..c220687 100644 --- a/gapi.js +++ b/gapi.js @@ -105,9 +105,21 @@ angular.module('gapi', []) /** - * OAuth 2.0 Signatures + * Credential exclusive way: API-key or Oauth 2.0 */ + function credential(options) { + if (GAPI.app.apiKey && !GAPI.app.clientId) { + setApiKey(options); + } else { + oauthHeader(options); + } + } + + function setApiKey(options) { + options.params.key = GAPI.app.apiKey; + } + function oauthHeader(options) { if (!options.headers) { options.headers = {}; } options.headers['Authorization'] = 'Bearer ' + GAPI.app.oauthToken.access_token; @@ -126,7 +138,7 @@ angular.module('gapi', []) function request (config) { var deferred = $q.defer(); - oauthHeader(config); + credential(config); function success(response) { $log.log('Request success: ', config, response);