люди API - не может получить доступ к связи людей - PullRequest
0 голосов
/ 11 марта 2019
  <script type="text/javascript">

    var CLIENT_ID = '775284796298-fhq44nljjvud5lg80kv0f72486c3luo0.apps.googleusercontent.com';
    var API_KEY = 'AIzaSyBgilBOzUy4V9WsmgnIKgIJ4bLnW-nmaSM';


    var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/people/v1/rest"];

    var SCOPES =  "https://www.googleapis.com/auth/contacts https://www.googleapis.com/auth/contacts.readonly"
    var authorizeButton = document.getElementById('authorize_button');
    var signoutButton = document.getElementById('signout_button');

    function handleClientLoad() {
      gapi.load('client:auth2', initClient);
    }

  function initClient() {
      gapi.client.init({
        apiKey: API_KEY,
        clientId: CLIENT_ID,
        discoveryDocs: DISCOVERY_DOCS,
        scope: SCOPES
      }).then(function () {

        gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);


        updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
        document.getElementById('authorize_button').onclick = handleAuthClick;
        document.getElementById('signout_button').onclick = handleSignoutClick;
      }, function(error) {
        appendPre(JSON.stringify(error, null, 2));
      });
    }


    function updateSigninStatus(isSignedIn) {
      if (isSignedIn) {
        document.getElementById('authorize_button').style.display = 'none';
        document.getElementById('signout_button').style.display = 'block';
        listConnectionNames();
      } else {
        document.getElementById('authorize_button').style.display = 'block';
        document.getElementById('signout_button').style.display = 'none';
      }
    }


    function handleAuthClick(event) {
      gapi.auth2.getAuthInstance().signIn();
    }


    function handleSignoutClick(event) {
      gapi.auth2.getAuthInstance().signOut();
    }


    function appendPre(message) {
      var pre = document.getElementById('content');
      var textContent = document.createTextNode(message + '\n');
      pre.appendChild(textContent);
    }


    function listConnectionNames() {
      gapi.client.people.people.connections.list({
      "resourceName": "people/me",
      "personFields": "names"
      }).then(function(response) {
        console.log(response)
      });
    }

  </script>

  <script async defer src="https://apis.google.com/js/api.js"
    onload="this.onload=function(){};handleClientLoad()"
    onreadystatechange="if (this.readyState === 'complete') this.onload()">
  </script>

Заголовок

Я пытаюсь получить список подключенных людей, но получаю сообщение об ошибке В запросе отсутствуют необходимые учетные данные для аутентификации.Ожидаемый токен доступа OAuth 2, файл cookie для входа или другие действительные учетные данные для аутентификации.Я могу выполнять операции получения людьми и отображать имя пользователя, но не могу получить доступ к деталям соединений.

...