如何同步 Google 和应用日历

how sync Google and app calendar

我正在尝试在日历应用程序中使用 google 日历。我想让用户在应用程序日历中同步他的 google 日历事件。这是我的代码

<script async defer src="https://apis.google.com/js/api.js"
     onload="this.onload=function(){};handleClientLoad()"
     onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>                                                    
<script>function handleClientLoad()
        {
            gapi.load('client:auth2', initClient);
        }
        function initClient() {
            gapi.client.init({
                discoveryDocs: DISCOVERY_DOCS,
                clientId: CLIENT_ID,
                scope: SCOPES
            }).then(function(){
                loadEvents();
            })
        }
function loadEvents()
        {
            gapi.client.calendar.events.list({
                'calendarId': '<?=$option['selected']?>',
                'timeMin': (new Date()).toISOString(),
                'showDeleted': false,
                'singleEvents': true,
                'maxResults': 10,
                'orderBy': 'startTime'
            }).then(function(response) {    
                var gEvents = response.result.items;                            
            })

对我来说它工作正常但对用户来说显示授权错误。我该如何解决它。我需要为用户发送授权密钥。

如果您遇到授权问题,可以检查these 点。您的错误已在文档中指定,可以通过以下方式解决:

  • Get a new access token using the long-lived refresh token.
  • If this fails, direct the user through the OAuth flow, as described in Authorizing requests with OAuth 2.0.
  • If you are seeing this for a service account, check that you have successfully completed all the steps in the service account page.