Google Calendar API获取“无法读取null的属性" signIn" [英] Google Calendar API getting 'Cannot read property 'signIn' of null'

查看:110
本文介绍了Google Calendar API获取“无法读取null的属性" signIn"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google的Calendar API获取有关特定日历的信息.我不断收到此错误无法读取null的属性'signIn'.我在此处在线使用示例 https://developers.google.com/google-apps/calendar/quickstart/js .

I'm trying to use Google's Calendar API to get info on specific calendar. I keep getting this error Cannot read property 'signIn' of null. I'm using the example online here https://developers.google.com/google-apps/calendar/quickstart/js.

知道为什么会这样吗?有人可以给我一种更简单的方式来获取日历数据吗?基本上,我想知道日历供稿中的哪些房间可以免费预订.我可以使用日历API来做到这一点吗?

Any idea why this is happening? And can someone give me a more simple way to get calendar data? Basically I want to know which rooms in my calendar feed are free to book. Can I do this using the calendar 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

}]);

推荐答案

尝试使用 gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus); 而不是 gapi.auth2.getAuthInstance().signIn(); .您可以参考以下示例代码来了解如何使用Google JavaScript客户端API库,用于对API进行身份验证并与之交互.

Try using gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus); instead of gapi.auth2.getAuthInstance().signIn();. You may refer with this sample code on how to use the Google JavaScript Client API Library to authenticate and interact with the API.

还要检查此相关的SO线程,看看是否它会有所帮助.

Also check this related SO thread and see if it helps.

更新:

关于如何检查日历上哪些房间是否可用的任何想法?

您可以点击以下链接: Google日历Api,有会议室吗??

You may check on this link: Google Calendar Api, Is meeting Room available?

您将需要通过身份验证才能访问该房间.然后,您可以使用Calendar Resource API的resourceEmail字段,并将其用作 events.list()日历API调用.

这篇关于Google Calendar API获取“无法读取null的属性" signIn"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆