Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down
16 changes: 14 additions & 2 deletions gapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down