以下代码用于 Window Live 联系人 API 以从中获取所有电子邮件地址。它在登录、注销和其他身份验证中运行良好。我可以通过函数调用收集登录用户的所有用户信息Get Data
,但是正在获取用户的电子邮件哈希,其余的电子邮件哈希是空白的。我的通讯录中有 10 个电子邮件地址。
如何使用此 api 获取联系人的电子邮件地址?
<html>
<head>
<script src="https://js.live.net/v5.0/wl.js" type="text/javascript"></script>
</head>
<body>
<a href='javascript:void(0);' onclick='signUserIn();'>signUserIn</a> <br>
<a href='javascript:void(0);' onclick='signUserOut()'>signUserOut</a><br>
<a href='javascript:void(0);' onclick='loginStatus()'>Check User Status</a>
<a href='javascript:void(0);' onclick='getData()'>Get Data</a>
<script type="text/javascript" >
WL.init({
client_id: '0000000044444444',
redirect_uri: 'http://domain.com/contact.php',
response_type: "token",
logging: true
});
var scopesArr = ['wl.signin', 'wl.basic', 'wl.emails'];
function signUserIn() {
WL.login({ scope: scopesArr });
}
function loginStatus() {
WL.getLoginStatus(function(response) {
alert("response " + response );
});
}
function getData() {
alert( "getData");
WL.api(
{
path: "me/contacts",
method: "GET",
scope: scopesArr
},
function (result) {
if (!result.error) {
var resultData = result.data;
var emailHashes = new Array;
for (i = 0; i < resultData.length; i++) {
for (j = 0; j < resultData[i].email_hashes.length; j++) {
alert( "resultData " + resultData[i].email_hashes[j]);
emailHashes[emailHashes.length] = resultData[i].email_hashes[j];
}
}
var resultText = "";
for (k = 0; k < emailHashes.length; k++) {
resultText += emailHashes[k] + "\r\n";
}
// document.getElementById("emailHashes").setAttribute("rows", emailHashes.length);
document.getElementById("lists").value = resultText;
}
else {
alert("Error getting contacts: " + result.error.message);
}
});
}
function signUserOut() {
WL.logout();
}
</script>
<textarea rows="10" cols="100" id="lists"></textarea>
</body>
</html>