Browse Source

Added facebook group search

gh-pages
Titouan Rigoudy 11 years ago
parent
commit
6b4c3fa99e
3 changed files with 84 additions and 16 deletions
  1. +67
    -13
      fb.js
  2. +14
    -3
      index.html
  3. +3
    -0
      style.css

+ 67
- 13
fb.js View File

@ -1,21 +1,24 @@
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
testAPI();
$("#fblogin").addClass("displaynone");
FB.api('/me', function (response) {
checkPermissionsById(response.id, facebookOk);
});
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
$('#status').html('Please log into this app.');
$("#fblogin").removeClass("displaynone");
$('#fbstatus').html('Please log into this app:');
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
$('#status').html('Please log into Facebook.';
$("#fblogin").removeClass("displaynone");
$('#fbstatus').html('Please log into Facebook:');
}
}
@ -64,14 +67,65 @@ window.fbAsyncInit = function() {
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
$('#status').html(
'Thanks for logging in, ' + response.name + '!');
function checkPermissionsById(user_id, success) {
FB.api('/' + user_id + '/permissions', function (response) {
var groups_granted = false;
$.each(response.data, function (i, val) {
console.log(val);
if (val.permission === 'user_groups' &&
val.status === 'granted')
groups_granted = true;
});
if (groups_granted)
success();
else
$('#fbstatus').html('You have not granted SpaceRadio the ' +
'permission to see your groups. Please log out of ' +
'Facebook and try again.');
});
}
function facebookOk() {
$("#fbloginbutton").addClass("displaynone");
$("#choosegroup").removeClass("displaynone");
}
var groups = [];
function findGroup() {
var group_name = $("#groupname").val();
var group_status = $("#groupstatus");
var group_results = $("#groupresults");
group_status.html("Searching for \"" + group_name + "\"");
group_results.html("");
if (groups.length != 0)
filterGroups(groups, group_name);
else
FB.api('/me/groups', function (response) {
groups = response.data;
filterGroups(response.data, group_name);
});
}
function filterGroups(group_list, group_name) {
var found = false;
var group_results = $("#groupresults");
var group_status = $("#groupstatus");
$.each(group_list, function (i,val) {
if (val.name.indexOf(group_name) >= 0) {
var link = $("<a/>", { text: val.name,
href: "javascript:processGroupFeed(" + val.id + ")"
});
link.appendTo(group_results).wrap("<li>");
found = true;
}
});
if (!found)
group_status.html("No result for \"" + group_name + "\"");
}
function processGroupFeed(group_id) {
console.log("Processing group " + group_id);
}

+ 14
- 3
index.html View File

@ -5,6 +5,7 @@
<meta charset="UTF-8">
</head>
<body>
<link rel="stylesheet" type="text/css" href="style.css">
<script id="jquery" src="http://code.jquery.com/jquery-2.1.1.min.js">
</script>
<script id="fbscript" src="fb.js">
@ -15,10 +16,20 @@
the JavaScript SDK to present a graphical Login button that triggers
the FB.login() function when clicked.
-->
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<div id="fblogin" class="displaynone">
<div id="fbstatus">
</div>
<fb:login-button scope="public_profile, user_groups" onlogin="checkLoginState();">
</fb:login-button>
</div>
<div id="status">
<div id="choosegroup" class="displaynone">
<label for="groupname">Facebook group to use:</label>
<input type="text" id="groupname" name="groupname" oninput="findGroup()">
<div id="groupstatus">
</div>
<ul id="groupresults">
</ul>
</div>
</body>


+ 3
- 0
style.css View File

@ -0,0 +1,3 @@
.displaynone {
display: none;
}

Loading…
Cancel
Save