简体   繁体   English

如何同步Google和应用程序日历

[英]how sync Google and app calendar

I'am trying to use google calendar in calendar application. 我正在尝试在日历应用程序中使用Google日历。 I want to let user syncronize his google calendar events in app calendar. 我想让用户在应用程序日历中同步他的Google日历事件。 This is my code 这是我的代码

<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;                            
            })

For me it works fine but for users shows authorization error. 对我来说,它工作正常,但对用户而言,显示授权错误。 How can I fix it. 我该如何解决。 I need to send authorization key for users. 我需要为用户发送授权密钥。

If you are having issues with authorization, you can check these points. 如果授权有问题,可以检查这些要点。 Your error was specified in the documentation and can be resolved by the following: 您的错误已在文档中指定,可以通过以下方法解决:

  • 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 . 如果失败, 请按照OAuth 2.0中的授权请求中所述,通过OAuth流程指导用户。
  • If you are seeing this for a service account, check that you have successfully completed all the steps in the service account page . 如果您在服务帐户中看到此信息,请检查是否已成功完成服务帐户页面中的所有步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM