2012-05-18 190 views
1

尝试允许用户使用Google日历API v3和javascript对事件进行身份验证和快速添加事件。我没有看到验证按钮。我对编码非常不熟悉。Google Calendar API Javascript Quickadd

控制台:

Uncaught SyntaxError: Unexpected token } test.html:47 
Uncaught TypeError: Cannot read property 'qainput' of undefined test.html:62 
onload test.html:62 

HTML文件:

<html> 
    <head> 
    <meta charset='utf-8' /> 
    <style> 
     #info { 
     border: 0px solid black; 
     padding: 0.25em; 
     margin: 0.5em 0; 
     } 
    </style> 
    <script type="text/javascript"> 
     var apiKey = 'AIzaSyDcbjOvAT85hCdVrjgUAqylf_QtxE2Gx60'; 
     var clientId = '202852486259.apps.googleusercontent.com'; 
     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) { 
     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 makeRpcRequest() { 
     var qatext = document.qaform.qainput.value; 
     var request = gapi.client.calendar.events.quick_add({ 
      'calendarId': 'primary', 
      'text': +qatext+ 
     }); 
     request.execute(writeResponse); 
     } 

     function writeResponse(response) { 
     console.log(response); 
     var name = response.summary; 
     var infoDiv = document.getElementById('info'); 
     var infoMsg = document.createElement('P'); 
     infoMsg.appendChild(document.createTextNode(+ name' sucessfully created!')); 
     infoDiv.appendChild(infoMsg); 
     } 
    </script> 
    <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script> 
    </head> 
    <body onload="document.qaform.qainput.focus();"> 
    <button id="authorize-button" style="visibility: hidden">Authorize to Use QuickAdd</button> 
    <form id="qaform"> 
    <input placeholder='QuickAdd' name='qainput' /> 
    <button id="rpc" onclick="makeRpcRequest();">Add</button> 
    </form> 
    <div id="info"></div> 
    </body> 
</html> 
+0

什么是'+ qatext +'和'createTextNode(+ name'成功创建!')'? – rxgx

回答

1

由于它是一个几个星期,你可能已经发现你的答案,但我也有同样的问题,最近开始基本上与您使用的代码基本相同。我根本没有在谷歌控制台的“服务”下激活谷歌日历。如果所有控制台设置都不正确,“授权”按钮将保持隐藏状态(默认情况下隐藏)。一旦所有设置都正确并且脚本与api正确通信,授权按钮将变得可见,然后您可以添加事件并通过单击按钮来编写响应。