forked from ccoenraets/OpenFB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (84 loc) · 3.14 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>openFB Sample</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="ratchet.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<button class="btn btn-block" onclick="login()">Login with Facebook</button>
<hr/>
<button class="btn btn-block" onclick="getInfo()">Get My Info</button>
<p>Name: <span id="userName"></span></p>
<img id="userPic"/>
<hr/>
<textarea id="Message" placeholder="What's on your mind?" rows="5"></textarea>
<button class="btn btn-block" onclick="share()">Share</button>
<hr/>
<p>Complete Facebook Logout. After logging out, you'll have to login again and provide your Facebook credentials.</p>
<button class="btn btn-block" onclick="logout()">Logout</button>
<hr/>
<p>Revoke App Permissions. After revoking permissions, you'll have to grant permissions again when logging in.</p>
<button class="btn btn-block" onclick="revoke()">Revoke Permissions</button>
<!--cordova.js is automatically injected by the Cordova build process-->
<script src="cordova.js"></script>
<script src="openfb.js"></script>
<script>
// Defaults to sessionStorage for storing the Facebook token
openFB.init({appId: 'YOUR_FB_APP_ID'});
// Uncomment the line below to store the Facebook token in localStorage instead of sessionStorage
// openFB.init({appId: 'YOUR_FB_APP_ID', tokenStore: window.localStorage});
function login() {
openFB.login(
function(response) {
if(response.status === 'connected') {
alert('Facebook login succeeded, got access token: ' + response.authResponse.token);
} else {
alert('Facebook login failed: ' + response.error);
}
}, {scope: 'email,read_stream,publish_stream'});
}
function getInfo() {
openFB.api({
path: '/me',
success: function(data) {
console.log(JSON.stringify(data));
document.getElementById("userName").innerHTML = data.name;
document.getElementById("userPic").src = 'http://graph.facebook.com/' + data.id + '/picture?type=small';
},
error: errorHandler});
}
function share() {
openFB.api({
method: 'POST',
path: '/me/feed',
params: {
message: document.getElementById('Message').value || 'Testing Facebook APIs'
},
success: function() {
alert('the item was posted on Facebook');
},
error: errorHandler});
}
function revoke() {
openFB.revokePermissions(
function() {
alert('Permissions revoked');
},
errorHandler);
}
function logout() {
openFB.logout(
function() {
alert('Logout successful');
},
errorHandler);
}
function errorHandler(error) {
alert(error.message);
}
</script>
</body>
</html>