使用javascript插入谷歌日历活动,代码为:404错误

时间:2015-03-24 09:34:29

标签: javascript google-calendar-api

我的代码如下:

<script type="text/javascript">
    var clientId = 'My Cient ID';
    var apiKey = 'My API Key';
    var scopes = 'https://www.googleapis.com/auth/calendar';
    function handleClientLoad() {
        gapi.client.setApiKey(apiKey);
        window.setTimeout(checkAuth,1);
    }

    function checkAuth() {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
    }
    function handleAuthResult(authResult) {
        if (authResult && !authResult.error)                    
          makeApiCall();                                            
        else {                                              
            handleAuthClick;                
        }
    }
    function handleAuthClick() {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
        return false;
    }
    var resource = {
        "summary": "Sample Event ",
        "start": {
            "dateTime": "2015-03-26T15:00:00.000-07:00"
        },
        "end": {
            "dateTime": "2015-03-26T16:00:00.000-07:00"
        }
    };
    function makeApiCall() {
        gapi.client.load('calendar', 'v3', function() {                 
            var request = gapi.client.calendar.events.insert({
                'calendarId':       'primary111111',    
                "resource":         resource                            
            });
            request.execute(function(resp) {
                if(resp.status=='confirmed') 
                    alert("success"); 
                else 
                console.log(resp);
            });
        });
    }
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

但是控制台总是给出 对象{代码:404,数据:数组[1],消息:“未找到”,错误:对象}。

为浏览器应用设置了api密钥,并为Web应用设置了客户端ID。任何人都可以帮助我吗?

0 个答案:

没有答案