-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfacebookconnect.js
More file actions
92 lines (88 loc) · 2.92 KB
/
Copy pathfacebookconnect.js
File metadata and controls
92 lines (88 loc) · 2.92 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
window.fbAsyncInit = function () {
FB.Event.subscribe('auth.statusChange', function (response) {
$(document).trigger('fbStatusChange', response);
});
FB.init({
appId: 'XXXXX', // App ID
channelUrl: '//localhost/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
var facebookconnect = {
getStatusFB: function() {
FB.getLoginStatus(function (response) {
$(document).trigger('fbStatusChange', response);
});
},
loginFB: function (callback) {
FB.login(function (response) {
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
//Do something when you have allready log in, like update UI
callback(true);
} else {
//User cancelled login or did not fully authorize. You should show on the UI
callback(false);
}
});
}, {
scope: 'email, user_likes, offline_access, publish_stream, read_stream'
});
},
postFB: function (act) {
var link = "\n see the pump -> " + act.attributes.object.url;
var str = act.attributes.object.content + link;
var regex = /<br\s*[\/]?>/gi;
str = str.replace(regex, "\n");
var body = str;
FB.api('/me/feed', 'post', {
message: body
}, function(response) {
if (!response || response.error) {
console.log('Error occured');
}
});
},
getPlace: function (latlon, callback) {
var url = '/search?type=place¢er=' + latlon + '&distance=1000';
FB.api(url, function(response) {
callback(response);
});
},
getPlaceLink: function (id, callback) {
var url = '/' + id;
FB.api(url, function(response) {
callback(response);
});
},
postPlaceFB: function (act, id, text) {
var link = "\n see the pump -> " + act.attributes.object.url;
var str = text + link;
var regex = /<br\s*[\/]?>/gi;
str = str.replace(regex, "\n");
FB.api('/me/feed', 'post', {
message: str,
place: id
}, function(response) {
if (!response || response.error) {
console.log('Error occured');
} else {
console.log(response);
}
});
}
};