-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
68 lines (63 loc) · 2.09 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>These Days Best Friends</title>
<style>
body { font-family: sans-serif; color: #333; }
</style>
</head>
<body>
<div id="fb-root"></div>
<p>Login status: <span id="login-status">...</span></p>
<p><a href="#" id="btn-get-best-friends">Get best friends</a></p>
<p id="results"></p>
<p><a href="https://github.com/thesedays/tdbestfriends">Source code on GitHub</a></p>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script src="tdbestfriends.js"></script>
<script>
(function(FB) {
var getBestFriends, bestFriends,
button = document.getElementById("btn-get-best-friends"),
results = document.getElementById("results");
// Initialise Facebook SDK
FB.init({ appId: "164829496916322", status: true, cookie: true, xfbml: false });
FB.getLoginStatus(function(response) {
var status = document.getElementById("login-status");
if (response.session) {
status.innerHTML = "Logged in";
TDBestFriends.setUid(response.session.uid);
TDBestFriends.setPerms(response.perms);
} else {
status.innerHTML = "Not logged in";
}
});
// Set options for TDBestFriends
TDBestFriends.setFB(FB);
TDBestFriends.extendOptions({
numToReturn : 10,
pagesToLoad : 2
});
// If you have already loaded the friends, pass them in to avoid another API call:
//TDBestFriends.setFriends(friends);
// Get the best friends when the link is clicked
getBestFriends = function(e) {
e.preventDefault();
TDBestFriends.getBestFriends(function(result) {
var i, len, html = '';
bestFriends = result;
for (i = 0, len = bestFriends.length; i < len; i += 1) {
html += (i + 1).toString() + '. ' + bestFriends[i].name + ' (' + bestFriends[i].id + ')<br>';
}
results.innerHTML = html;
});
};
if (button.addEventListener) {
button.addEventListener("click", getBestFriends, false);
} else if (button.attachEvent) {
button.attachEvent("onclick", getBestFriends);
}
}(FB));
</script>
</body>
</html>