Google API javascript客户端 - 未捕获的TypeError

时间:2015-08-05 19:16:33

标签: javascript api google-plus

我尝试连接Google客户端API以获取客户端的一些基本信息(姓名,电子邮件...)。

所以我使用this tutorial尝试连接客户端API。

我按照所有说明操作,在Google Developper Console上创建了OAuth客户端。

把我的"客户ID和#34;和#34;客户端秘密"在" var Client ID"和" apiKey"在下面的代码:



<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />
  </head>
  <body>
    
    <button id="authorize-button" style="visibility: hidden">Authorize</button>
    
    <script type="text/javascript">
      
      var clientId = 'xxxxxxxxxxxxxxxxxxxxx';
      
      var apiKey = 'xxxxxxxxxxxxxxxxxxx';
           
      var scopes = 'https://www.googleapis.com/auth/plus.me';
      
      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 && !authResult.error) {
          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('plus', 'v1', function() {
          var request = gapi.client.plus.people.get({
            'userId': 'me'
          });
          request.execute(function(resp) {
            var heading = document.createElement('h4');
            var image = document.createElement('img');
            image.src = resp.image.url;
            heading.appendChild(image);
            heading.appendChild(document.createTextNode(resp.displayName));
            document.getElementById('content').appendChild(heading);
          });
        });
      }
    </script>
    <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
    <div id="content"></div>
    <p>Retrieves your profile name using the Google Plus API.</p>
  </body>
</html>
&#13;
&#13;
&#13;

但是当我点击&#34;授权按钮&#34;并在同意屏幕上接受条款,控制台告诉我这两个错误:

"GET https://content.googleapis.com/discovery/v1/apis/plus/v1/rest?fields=rootUr…ePath%2Cresources%2Cparameters%2Cmethods&pp=0&key=ADEcoJRjS6zPKeWplLfNTCiJ 400 (OK)

Uncaught TypeError: Cannot read property 'people' of undefined"

所以,我的客户端未定义,这怎么可能?我到处搜索,但没有找到解决方案,我真的很陌生。

0 个答案:

没有答案