0

I'm integrating Google picker API in my application. I'm following the official documentation Google Picker API

I have successfully done my job, but after adding below code I am unable to use class methods and variables. Getting Cannot read property of undefined error

gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});

Complete code is:

onApiLoad() {
    var a= this;
    gapi.load('auth', {'callback': this.onAuthApiLoad.bind(a)});
    gapi.load('picker');
  }

  onAuthApiLoad() {
    gapi.auth.authorize(
        {
          'client_id': this.clientId,
          'scope': this.scope,
          'immediate': false
        },
        this.handleAuthResult);
  }

  handleAuthResult(authResult) {
    if (authResult && !authResult.error) {
      if (authResult.access_token) {
        var pickerBuilder = new google.picker.PickerBuilder();
        var picker = pickerBuilder.
            enableFeature(google.picker.Feature.NAV_HIDDEN).
            setOAuthToken(authResult.access_token).
            addView(google.picker.ViewId.DOCS).
            setCallback(this.myFun).
            build();
        picker.setVisible(true);
      }
    }
  }

  myFun(e){

}
Rama Krishna
  • 645
  • 10
  • 28

1 Answers1

0

I have added below line to handle auth request

this.handleAuthResult.bind(this)
Rama Krishna
  • 645
  • 10
  • 28