-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmine.php
More file actions
118 lines (106 loc) · 4.16 KB
/
mine.php
File metadata and controls
118 lines (106 loc) · 4.16 KB
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
<script>
function dump(obj) {
var out = '';
for (var i in obj) {
out += i + ": " + obj[i] + "\n";
}
return out;
}
function fbLogin()
{
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
displayMine();
});
} else {
$('#loginStatus').html('User cancelled login or did not fully authorize.');
}
}, {scope: 'read_stream'});
}
function checkPerms() {
FB.api('/me/permissions', function(perms_response) {
if(perms_response['data'][0]['read_stream']) {
displayMine();
} else {
fbLogin();
}
});
}
function displayMine() {
FB.api('/me/home', function(response) {
if (!response || response.error) {
$('#news').html('Error:'+response.error.code);
} else {
var urls = [];
var data = response.data;
var output = '<h2>Newsfeed</h2><ol>';
for(var i=0; i<data.length; i++) {
output += '<li>';
output += '<span class="post"><img class="profile" src="http://graph.facebook.com/'+data[i].from.id+'/picture" />';
output += '<a href="http://www.facebook.com/'+data[i].from.id+'" target="_blank"><i>'+
data[i].from.name+'</i></a> ';
output += data[i].message;
if(typeof data[i].link != 'undefined') {
output += '<br><a href="'+data[i].link+'" target="_blank">'+data[i].link+'</a>';
var obj = {};
obj.url = data[i].link;
obj.fromId = data[i].from.id;
obj.fromName = data[i].from.name;
urls.push(obj);
}
output += "</span></li>\n";
}
// Send list of links back to app
$.post('api.php?action=trk', {data: JSON.stringify(urls)});
output += '</ol><h2>Your Posts</h2><ol>';
FB.api('/me/posts', function(response) {
if (!response || response.error) {
$('#news').html('Error:'+response.error.code);
} else {
var urls = [];
var data = response.data;
for(var i=0; i<data.length; i++) {
output += '<li>';
output += data[i].message;
if(typeof data[i].link != 'undefined') {
output += ' - <a href="'+data[i].link+'" target="_blank">'+data[i].link+'</a>';
var obj = {};
obj.url = data[i].link;
obj.fromId = data[i].from.id;
obj.fromName = data[i].from.name;
urls.push(obj);
}
output += "</li>\n";
}
// Send list of links back to app
$.post('api.php?action=trk', {data: JSON.stringify(urls)});
}
output += '</ol>';
$('#news').html(output);
});
}
});
}
FBC.callback = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/me', function(response) {
checkPerms();
});
} else {
// the user isn't logged in to Facebook.
fbLogin();
}
});
}
</script>
<div id="loginStatus"></div>
<div id="news"><img src="img/indicator.gif" /></div>