Google Calendar API - 请求网址404未找到

时间:2015-03-21 00:44:52

标签: javascript events google-api google-calendar-api

我正在尝试使用Google API从我的日历中获取活动:

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script src="googleCalendar.js"></script>
        <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
    </head>
    <body>

        <div id="calendarContainer">
            <div>
                <button type="button" id="authorize-button"><?= _("Google Calendar Events"); ?></button>
            </div>

            <div id="content">
                <h2><?= _("Events"); ?></h2><br>
                <ul id="events"></ul>
            </div>
        </div>

    </body>
</html>

googleCalendar.js:

$(document).ready(function() {
    var clientId = '{my_client_id}';
    var apiKey = '{my_api_key}';
    var scopes = 'https://www.googleapis.com/auth/calendar';

    $("#authorize-button").click(function(){
        handleClientLoad();
    });

    function handleClientLoad()
    {
        gapi.client.setApiKey(apiKey);
        window.setTimeout(checkAuth,1);
        checkAuth();
    }

    function checkAuth()
    {
        gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
        handleAuthResult);
    }

    function handleAuthResult(authResult)
    {
        var authorizeButton = document.getElementById('authorize-button');
        if (authResult) {
            //authorizeButton.style.visibility = 'hidden';
            makeApiCall();
        } else {
            authorizeButton.style.visibility = '';
            authorizeButton.onclick = handleAuthClick;
        }
    }

    function handleAuthClick(event)
    {
        gapi.auth.authorize(
            {client_id: clientId, scope: scopes, immediate: false},
            handleAuthResult
        );
        return false;
    }

    function makeApiCall()
    {
        gapi.client.load('calendar', 'v3', function() {
            var request = gapi.client.calendar.events.list({
                'calendarId': 'primary'
            });

            request.execute(function(resp) {
                console.log(resp);
                for (var i = 0; i < resp.items.length; i++) {
                    var li = document.createElement('li');
                   li.appendChild(document.createTextNode(resp.items[i].summary));
                document.getElementById('events').appendChild(li);
                }
            });
        });
    }

});

当我点击按钮以获取我的活动时,我什么也得不到。然后我检查我的页面,我得到了这个:

  

请求网址:   https://content.googleapis.com/calendar/v3/calendars/primary/events?key= {my_api_key}

     

状态代码:404未找到

在我的浏览器中粘贴该URL我得到了:

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "notFound",
                "message": "Not Found"
            }
        ],
        "code": 404,
        "message": "Not Found"
    }
}

为什么我找不到404,而且我没有从日历中获取事件列表?

0 个答案:

没有答案