2015-09-17 3 views
0

Я пытаюсь использовать API Plus подписать пользователя в я получаю следующее сообщение об ошибке в консоли:.«Uncaught TypeError: Не удается прочитать свойство„людей“неопределенных»

Uncaught TypeError: Не удается прочитать свойство " люди»неопределенного

Адрес страницы: http://fbconnect.yudazdk.com/google_connect.php

Мой код:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Google Connect JavaScript test</title> 
    <meta charset="UTF-8"> 
</head> 

<body> 

<h2>Google Connect Test Page</h2> 
<button id="authorize-button" style="visibility: hidden">Authorize</button> 

<script type="text/javascript"> 

    <!--Add a button for the user to click to initiate auth sequence --> 

    var clientId = 'xxxxx-09ecq1a33q91tvsd50rd2g5n0qiuortd.apps.googleusercontent.com'; 

    var apiKey = 'xxxxxx'; 

    var scopes = 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me'; 
    scopes += ' https://www.googleapis.com/auth/userinfo.email'; 

    function handleClientLoad() { 
     // Step 2: Reference the API key 
     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) { 
      console.log('auth result'); 
      console.log(authResult); 
      authorizeButton.style.visibility = 'hidden'; 
      makeApiCall(); 
     } else { 
      authorizeButton.style.visibility = ''; 
      authorizeButton.onclick = handleAuthClick; 
     } 
    } 

    function handleAuthClick(event) { 
     // Step 3: get authorization to use private data 
     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) { 
       console.log('Retrieved profile for:'); 
       console.log(resp); 
      }); 
     }); 
    } 

    // Load the API and make an API call. Display the results on the screen. 
    function makeApiCall1() { 
     // Step 4: Load the Google+ API 
     gapi.client.load('plus', 'v1').then(function() { 
      // Step 5: Assemble the API request 
      var request = gapi.client.plus.people.get({ 
       'userId': 'me' 
      }); 
      // Step 6: Execute the API request 
      request.then(function(resp) { 
       var heading = document.createElement('h4'); 
       var image = document.createElement('img'); 
       image.src = resp.result.image.url; 
       heading.appendChild(image); 
       heading.appendChild(document.createTextNode(resp.result.displayName)); 

       document.getElementById('content').appendChild(heading); 
      }, function(reason) { 
       console.log('Error: ' + reason.result.error.message); 
      }); 
     }); 
    } 

</script> 

<!-- Step 1: Load JavaScript client library --> 
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script> 

</body> 
</html> 

ответ

1

Проблема решена. Это был неправильный ключ API.

Сценарий не был загружен так я предположил, что это было неправильно API ключ, который был правильным предположение о том

+0

Большое вам спасибо. У меня была такая же проблема. –

0

Althought в gapi.client.load имеет третий параметр необязательный, но люди наблюдали ошибки при его использовании с обещаниями ref: Undefined Error with Gapi.load

Попробуйте передать функцию обратного вызова, используя ее в качестве обещания.

function makeApiCall1() { 
     gapi.client.load('plus', 'v1',function() { 
      var request = gapi.client.plus.people.get({ 
       'userId': 'me' 
      }); 
      request.then(function(resp) { 
       var heading = document.createElement('h4'); 
       var image = document.createElement('img'); 
       image.src = resp.result.image.url; 
       heading.appendChild(image); 
       heading.appendChild(document.createTextNode(resp.result.displayName)); 

       document.getElementById('content').appendChild(heading); 
      }, function(reason) { 
       console.log('Error: ' + reason.result.error.message); 
      }); 
     }); 
    } 
+0

Я попробовал это. Это не помогло. Спасибо –

+0

Неужели вы все еще видите ту же ошибку? или его другой –

Смежные вопросы