我试图使用Google的Calendar API来获取特定日历上的信息。我不断收到此错误Cannot read property 'signIn' of null
。我在这里使用在线示例https://developers.google.com/google-apps/calendar/quickstart/js。Google Calendar API获取'无法读取属性'登录'null'
任何想法为什么会发生这种情况?有人可以给我一个更简单的方法来获取日历数据?基本上我想知道我的日历Feed中的哪些房间可以免费预订。我可以使用日历API来做到这一点吗?
const CLIENT_ID = '418414126140-u5u3r2ampke8egh7d2tk50ferkl8ri26.apps.googleusercontent.com';
const SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"];
app.factory('getCalendar', ['$q', function($q){
return function checkAuth() {
var deferred = $q.defer();
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
handleClientLoad();
function initClient() {
gapi.client.init({
"client_id": CLIENT_ID,
"scope": SCOPES
}).then(function() {
gapi.auth2.getAuthInstance().signIn();
});
}
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
console.log("You are authorized");
listUpcomingEvents();
} else {
console.log("You are not authorized");
}
}
function listUpcomingEvents() {
gapi.client.calendar.events.list({
'calendarId': 'primary',
'timeMin': (new Date()).toISOString(),
'showDeleted': false,
'singleEvents': true,
'maxResults': 10,
'orderBy': 'startTime'
}).then(function(response) {
console.log(response);
deferred.resolve(response);
});
}
return deferred.promise;
} //return ends here
}]);
谢谢。我发现这个在线教程比谷歌的文档更容易使用。 https://www.youtube.com/watch?v=0rZmp3Ew_kA 有关如何检查日历上的哪些房间可用或不可用的任何想法? –