Skip to content

Instantly share code, notes, and snippets.

@superlou
Created March 19, 2015 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superlou/4d6d610ba1537c21548b to your computer and use it in GitHub Desktop.
Save superlou/4d6d610ba1537c21548b to your computer and use it in GitHub Desktop.
g-drive.js
import Ember from 'ember';
var gDrive = Ember.Object.extend({
clientId: '937974467154-23re9rr70mnlkmuddvpp325abth5u51k.apps.googleusercontent.com',
scopes: ['https://www.googleapis.com/auth/drive', 'email'],
authed: false,
ready: false,
init: function() {
window.handleClientLoad = this.handleClientLoad.bind(this);
window.gDriveService = this;
Ember.$.getScript('https://apis.google.com/js/client.js?onload=handleClientLoad');
},
handleAuthResult: function(authResult) {
var _this = this;
console.log(authResult);
if (authResult && !authResult.error) {
this.set('authed', true);
gapi.client.load('drive', 'v2', function() {
_this.set('ready', true);
});
} else {
this.set('authed', false);
}
},
handleClientLoad: function() {
gapi.auth.authorize({
'client_id': this.get('clientId'),
'scope': this.get('scopes'),
'immediate': true,
}, this.handleAuthResult.bind(this)
);
},
presentAuth: function() {
gapi.auth.authorize({
'client_id': this.get('clientId'),
'scope': this.get('scopes'),
'immediate': false,
}, this.handleAuthResult.bind(this)
);
},
find: function(match) {
var request = gapi.client.drive.children.list({
'folderId': 'root'
})
request.execute(function(result) {
console.log(result);
});
}
});
export default gDrive;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment