-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
172 lines (155 loc) · 5.06 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Home | dePINdable</title>
<!-- Minified CSS bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style media="screen">
#fb-btn{margin-top: 16px;}
#profile,#logout,#friends{display: none;}
</style>
</head>
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '211179206119669',
cookie : true,
xfbml : true,
version : 'v2.11'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function statusChangeCallback (response) {
if (response.status === 'connected') {
console.log("Logged in and authenticated!");
setElements(true);
testAPI();
} else {
console.log("Cannot log in. Not Authenticated!\nPlease login to facebook to continue.");
setElements(false);
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
function setElements(isLoggedIn) {
if (isLoggedIn) {
document.getElementById('logout').style.display = 'block';
document.getElementById('profile').style.display = 'block';
document.getElementById('friends').style.display = 'block';
document.getElementById('fb-btn').style.display = 'none';
document.getElementById('heading').style.display = 'none';
} else {
document.getElementById('logout').style.display = 'none';
document.getElementById('profile').style.display = 'none';
document.getElementById('friends').style.display = 'none';
document.getElementById('fb-btn').style.display = 'block';
document.getElementById('heading').style.display = 'block';
}
}
function logout() {
FB.logout(function(response) {
setElements(false);
})
}
function testAPI() {
FB.api('/me?fields=name,about,email,location,birthday,friendlists{name},picture', function (response) {
if(response && !response.error) {
console.log(response);
buildProfile(response);
}
FB.api('/me/friends?limit=500', function (response) {
if(response && !response.error) {
for (let i in response.data){
if (response.data[i].id){
var id = response.data[i].id;
FB.api('/'+id+'/picture', function(response){
if(response && !response.error) {
console.log(response.data.url);
}
})
}
}
console.log(response);
buildFriends(response);
}
})
})
}
function buildProfile(user) {
let profile = `
<h3>${user.name}</h3>
<img id="profilePic" src ="${user.picture.data.url}" >
<br><br>
<ul class="list-group">
<li class="list-group-item">User ID: ${user.id}</li>
<li class="list-group-item">About: ${user.about}</li>
<li class="list-group-item">Email: ${user.email}</li>
<li class="list-group-item">Birthday: ${user.birthday}</li>
</ul>
`;
document.getElementById('profile').innerHTML = profile;
}
function buildFriends (friend) {
let output = '<h3>Pinned location by your friends</h3>'
if(friend.data){
for (let i in friend.data){
if (friend.data[i].name){
output += `
<div class="well">
${friend.data[i].name}
</div>
`;
}
}
}
document.getElementById('friends').innerHTML = output;
}
</script>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">dePINdable</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a id="navhome" href="index.html">Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a id="pinloc" href="pinlocation.html">Pin Your Location</a></li>
<li><a id="logout" href="" onclick="logout()">Logout</a></li>
<fb:login-button
id ="fb-btn"
scope="public_profile,email,user_about_me,user_location,user_birthday,user_friends,read_custom_friendlists"
onlogin="checkLoginState();">
</fb:login-button>
</ul>
</div>
</div>
</nav>
<div class="container">
<h3 id="heading">Log in to view your profile.</h3>
<div id="profile"></div>
<div id="friends"></div>
</div>
</body>
</html>