Google Drive Picker and Ionic

#1

I am trying to use the Google Picker within my Ionic App and I’ve run into a bit of a road block, where the authentication loads and the oauth token is returned, but when it returns back to the app, the app doesnt seem to be loaded anymore, or the state is gone. The object “this” does not exist any more.

https://developers.google.com/picker/docs/

When you run this, it pops into a new window and you agree to give access to your google drive

checkAuth() {
gapi.auth.authorize(
{
‘client_id’: CLIENT_ID,
‘scope’: this.SCOPES.join(’ '),
‘immediate’: false
}, this.handleAuthResult);
}

When it goes into handleAuthResult it no longer has access to this, and this.createPicker throws an error “Cannot read property ‘createPicker’ of undefined”

handleAuthResult(authResult) {
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
console.log(authResult);
alert(authResult.access_token);
console.log(this);
this.createPicker()
} else {
this.checkAuth();
}
}

// Create and render a Picker object for picking user Photos.
createPicker() {
let picker = new google.picker.PickerBuilder().
addView(google.picker.ViewId.PHOTOS).
setOAuthToken(this.oauthToken).
setDeveloperKey(this.developerKey).
setCallback(this.pickerCallback).
build();
picker.setVisible(true);
}