I'm back on the Facebook functionality I asked about earlier this week, something clientco want bolted onto their fantasy games web apps.
I got the "post comment to user's wall" working fine, but am having problems with the second requirement "invite friends to join game" (sample web page appears below).
The Facebook documentation is utter tulip, as they're constantly upgrading to new rubriks (if that's the right word) and what documentation exists is either very sketchy or absurdly geeky with nothing in between, and precious few decent examples. I imagine even O'Reilly are holding off for now on publishing a "Facebook Cookbook".
Anyway, enough whining. Here is the code. I know all the API keys and signatures etc are fine, and the Facebook channel file is being found (because as I said the "Post to Wall" functionality is working fine).
But if anyone can see any obvious reason why the "invite friends" button does nothing, it'll be a big help and much appreciated.
This is a third-party app by the way, which connects to Facebook via (at NickF's suggestion) Facebook Connect. So it doesn't run within the Facebook canvas or IFrame (or whatever Facebook are calling their "framework" today!)
(Please God, let NickF look in sometime this weekend! )
I mean for a start, what the flip's the difference between FB.Facebook.init() and FB.init() ?!
edit: POST_ACTION_URL is where the Facebook Javascript redirects after completing the action, i.e. back to the client's app. I blanked this out for client confidentiality reasons.
I got the "post comment to user's wall" working fine, but am having problems with the second requirement "invite friends to join game" (sample web page appears below).
The Facebook documentation is utter tulip, as they're constantly upgrading to new rubriks (if that's the right word) and what documentation exists is either very sketchy or absurdly geeky with nothing in between, and precious few decent examples. I imagine even O'Reilly are holding off for now on publishing a "Facebook Cookbook".
Anyway, enough whining. Here is the code. I know all the API keys and signatures etc are fine, and the Facebook channel file is being found (because as I said the "Post to Wall" functionality is working fine).
But if anyone can see any obvious reason why the "invite friends" button does nothing, it'll be a big help and much appreciated.
This is a third-party app by the way, which connects to Facebook via (at NickF's suggestion) Facebook Connect. So it doesn't run within the Facebook canvas or IFrame (or whatever Facebook are calling their "framework" today!)
(Please God, let NickF look in sometime this weekend! )
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
// Post comment on user's Facebook wall
//
function jsPostWall()
{
// Initialize facebook
//
FB_RequireFeatures(["Connect"], function()
{
// Create an ApiClient object, passing app's API key and a site relative URL to xd_receiver.htm
//
FB.Facebook.init('b8ca874634d495f76378c7ee8e1aded2', 'xd_receiver.htm');
FB.ensureInit(function()
{
// FB.Facebook.get_sessionState().waitUntilReady(function()
// {
FB.Connect.showPermissionDialog("publish_stream", function(perms)
{
if (perms == "publish_stream")
{
var message = 'JR test message text here'; // text user entered themselves
var attachment =
{
'name': 'JR test post name',
'href': window.location.href,
'caption': 'JR test post caption',
'description': 'JR test post description'
};
var action_links = [ { 'text': 'JR action text', 'href': 'http://www.google.com' } ];
var target_id = null; // post on user's wall (as opposed to friend's wall for example)
var auto_publish = false; // false => prompt for user approval even if they have previously granted publish_stream
var actor_id = null;
// see http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish
//
FB.Connect.streamPublish(message, attachment, action_links, target_id,
"JR test default text", callback, auto_publish, actor_id);
}
});
// });
});
});
function callback(post_id, exception)
{
alert('Wall Post Complete');
}
}
</script>
<fb:login-button></fb:login-button>
<div id="fb_users"></div>
<script type="text/javascript">
function jsInviteFriends()
{
// Initialize facebook
//
FB_RequireFeatures(["Connect"], function()
{
// Create an ApiClient object, passing app's API key and a site relative URL to xd_receiver.htm
//
FB.Facebook.init('b8ca874634d495f76378c7ee8e1aded2', 'xd_receiver.htm');
FB.ensureInit(function()
{
FB.Facebook.get_sessionState().waitUntilReady(function()
{
document.getElementById("fb_users").innerHTML =
(<r><![CDATA[
<fb:request-form action="POST_ACTION_URL" // URL blanked out [OH]
method="POST"
invite="true"
type="JR test invite title"
content="<fb:name uid="" firstnameonly="true" shownetwork="false"/> invites you to play a fantasy game
<fb:req-choice url="http://www.google.com" label="Google"/>
">
<fb:multi-friend-selector
max="20"
actiontext="Invite your friends to start playing this game today!"
showborder="true"
rows="5">
</fb:multi-friend-selector>
</fb:request-form>
]]></r>).toString();
FB.XFBML.Host.parseDomTree();
});
});
});
}
</script>
<br></br>
<a href="#" onclick="jsPostWall(); return false;">Post a story on your Facebook Wall!</a>
<br></br>
<a href="#" onclick="jsInviteFriends(); return false;">Invite your Facebook friends!</a>
</body>
</html>
edit: POST_ACTION_URL is where the Facebook Javascript redirects after completing the action, i.e. back to the client's app. I blanked this out for client confidentiality reasons.
Comment