<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或其他有效的身份验证凭据。 我能够执行操作并显示用户名,但无法访问连接详细信息。