Skip to content

Instantly share code, notes, and snippets.

@waitonza
Created October 31, 2012 15:55
Show Gist options
  • Save waitonza/3987859 to your computer and use it in GitHub Desktop.
Save waitonza/3987859 to your computer and use it in GitHub Desktop.
FaceBook Test For Fire Finger
<html>
<head>
<title>FaceBook Test For Fire Finger</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<h1>Facebook API Test</h1>
<h3>Friend List</h3>
<input type="button"
onclick="sendRequestViaMultiFriendSelector(); return false;"
value="Send Request to Many Users"
/>
<br>
<table border="1" id="FBfriendlist">
<tr>
<th>Picture</th>
<th>Name</th>
<th>Post to wall</th>
<th>Send Request</th>
</tr>
</table>
<div id="fb-root"></div>
<script>
var accessToken;
var userID;
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : '296376977130858', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional init code here
FB.getLoginStatus(function(response) {
console.log(response);
if (response.status === 'connected') {
// connected
console.log('Logined');
//logout();
accessToken = response.authResponse.accessToken;
userID = response.authResponse.userID;
friendListAPI();
} else if (response.status === 'not_authorized') {
// not_authorized
console.log('Not Autorized');
login();
} else {
// not_logged_in
console.log('Not Login');
login();
}
});
};
// 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));
function login() {
FB.login(function(response) {
if (response.authResponse) {
// connected
} else {
// cancelled
}
});
}
function friendListAPI() {
console.log('Welcome! Fetching your information.... ');
var url = '/me/friends?access_token=' + accessToken;
FB.api(url, function(response) {
console.log(response);
for (var i = 0; i < response.data.length; i++) {
var friend = response.data[i];
var x = document.getElementById("FBfriendlist");
var url = "https://graph.facebook.com/"+friend.id+"/picture";
var fun = 'postToFeed('+friend.id+')';
var request = 'sendRequestTo('+friend.id+')';
var z = '<tr><td><img src="'+url+'"></td><td>'+friend.name+'</td><td><button onclick="'+fun+'">Post it!</button></td><td><button onclick="'+request+'">Send it!</button></td></tr>';
x.innerHTML += z;
};
//console.log('Good to see you, ' + response.name + '.');
});
}
function logout() {
FB.logout(function(response) {
// user is now logged out
});
}
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
//alert("Post ID: " + response['post_id']);
}
FB.ui(obj, callback);
}
function postToFeed(sendto) {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
to: sendto,
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
//alert("Post ID: " + response['post_id']);
}
FB.ui(obj, callback);
}
function sendRequestTo(id) {
FB.ui({method: 'apprequests',
message: 'Fire Finger invite Request',
to: id
}, requestCallback);
}
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'Fire Finger invite Request'
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment