I am new to google calendar api and react so I'm sure there is something small I'm missing here. I cannot import the necessary google api libraries to call "gapi." I have try to import them like I would do from local libraries but still get the error "gapi is not defined". I need to use the "gapi" in my component so I don't think I can call and append the script to the body using the componentDidLoad.
// Libraries
import React, {Component} from 'react';
//...import other libraries
//import google libraries in order to use "gapi" and call "checkAuth"
import 'https://ajax.googleapis.com/ajax/libs/angularjs/1.2.32/angular.min.js';
import 'https://apis.google.com/js/client.js?onload=checkAuth';';
var CLIENT_ID = 'MY_CLIENT_ID_IS_HERE';
var SCOPES = ["https://www.googleapis.com/auth/calendar"];
class NewCalendar extends Component {
constructor(props) {
super(props);
this.checkAuth = this.checkAuth.bind(this);
}
checkAuth() {
console.log('checkAuth running...')
gapi.auth.authorize( //ISSUE
^issue with the last line
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, this.handleAuthResult);
}
...
}
export default NewCalendar;
Does anyone know how to resolve this issue?
Thanks a million.