views:

6391

answers:

2

I am developing facebook application in fb:iframe. I do not want to use "feed_publishUserAction" as it requires a session key. Hence trying to use FB.Connect.showFeedDialog. Is it ok to use the latter? Can any one suggest example to use it as I am getting an error saying "Call to undefined function showfeeddialog()". Shud I update my library?Any other suggestions?

+3  A: 

First of all, you need to make sure the client library is being included:

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

This should not be in the of the HTML page but in the body. From the docs:

Note: You must include the <script> tag that loads the FeatureLoader at the beginning of your <body> element. The FeatureLoader may write body elements directly > to the document, which, if it happens within the <head> element, is reported as an error by some browsers.

How are you calling the function? It should look something like:

FB.Connect.showFeedDialog(123456789, data);

(the numbers being the template id of the template you want to publish in, created in facebook or registered with the api. "data" should be the json you will populate said template with).

On thing to be aware of is that you need to make sure client library is ready to rock before you call any functions from it:

FB.ensureInit(function () { 
    // -- now library is officially ready
});

or check out the Waitable class:

http://wiki.developers.facebook.com/index.php/JS_API_T_FB.Waitable

Remember: you do have to have logged in via Facebook connect to use the showFeedDialog form. Also, having worked with the Connect API all week...it's still very beta and requires numerous workarounds. You should post some of your code so we can help further.

Typeoneerror
A: 

//function FBlogin() //{ FB.Bootstrap.requireFeatures(["Connect"], function() { FB.init("780e297634f1f1bd8f3a0a2e63100029","xd_receiver.htm",{"ifUserConnected" : update_user_box}); //FB.Connect.requireSession(); }); //} function FBlogin() { FB.Bootstrap.requireFeatures(["Connect"], function() { FB.init("780e297634f1f1bd8f3a0a2e63100029","xd_receiver.htm",{"ifUserConnected" : update_user_box}); FB.Connect.requireSession(); }); } Logout

Leave a comment:

 <!--FB connect button-->
 <fb:login-button onlogin="update_user_box();"></fb:login-button> 

 <div id="user"> Name: <input name="name" size="27"><br /> </div> 
 <textarea name="comment" rows="5" cols="30"></textarea> <br /> 
 <input type="hidden" name="facebook-request" value="true" />
 <input type="submit" value="Submit Comment"> 
</form> 
</div> 
<div>
<input type="button" name="friendlist" value="FB Friends List" onclick="FBfriends()">
<div id="fbfriends">
</div>
</div>
<?php
 if($_POST["comment"] != '')
 {
?>
 <script type="text/javascript"> 
  FB.ensureInit(function () { 
   // -- now library is officially ready
  });

  body_general = "Life sucks here.";
  user_message_prompt = "How ru guy's";
  user_message = "Life ends here.";
  template_data = {"comment":":"+user_message};

  FB.Connect.showFeedDialog('102397912126', template_data, ['1234567890'], body_general, null, FB.RequireConnect.require, callback, user_message_prompt, user_message);
  function callback()
  {
   alert('success.');
  }

 </script> 
<?php
 }
?>
<div>
 <input type="button" name="fbinvite" value="FB Invite" onclick="FBInvite()">
 <div id="FBInvite" style="visibility:hidden">
  <!-- Server FBML tags are necessary for Facebook elements which must be hosted on Facebook.  The request form is one of these, as demonstrated below.  See the documentation for a list of such elements.  --> 
  <fb:serverfbml style="width: 755px;">
   <script type="text/fbml">
    <fb:fbml>
    <fb:request-form 
      action="<url for post invite action, see wiki.developers.facebook.com for fb:request-form details>" 
      method="POST" 
      invite="true" 
      type="XFBML" 
      content="This is a test invitation from XFBML test app
      <fb:req-choice url='see wiki page for fb:req-choice for details' 
      label='Ignore the Connect test app!' />">
      <fb:multi-friend-selector 
     showborder="false" 
     actiontext="Invite your friends to use Connect.">
    </fb:request-form>
    </fb:fbml>
   </script>
  </fb:serverfbml>
 </div>
</div>
<script type="text/javascript">
function update_user_box() {

  var user_box = document.getElementById("user");

  // add in some XFBML. note that we set useyou=false so it doesn't display "you"
  user_box.innerHTML =
   "<span>"
 + "<fb:profile-pic uid='loggedinuser' facebook-logo='true'></fb:profile-pic>"
 + "Welcome, <fb:name uid='loggedinuser' useyou='false'></fb:name>. You are signed in with your Facebook account."
 + "</span>";

  // because this is XFBML, we need to tell Facebook to re-process the document 
  FB.XFBML.Host.parseDomTree();
}
function FBfriends()
{
 FB_RequireFeatures(["XFBML"], function()
 {
   FB.Facebook.get_sessionState().waitUntilReady(function()
   {
  //window.alert("Session is ready");
  //If you want to make Facebook API calls from JavaScript do something like
  FB.Facebook.apiClient.friends_get(null, function(result, ex) {
    //Do something with result     
   //window.alert("Friends list: " + result);
   document.getElementById("fbfriends").innerHTML = result;
    });

   });
 });
}
function FBInvite()
{
 if(document.getElementById("FBInvite").style.visibility == "visible")
 {
  document.getElementById("FBInvite").style.visibility = "hidden";
 }
 else
 {
  document.getElementById("FBInvite").style.visibility = "visible";
 }
}
</script>

Could you please tell me what's wrong in my code.

related questions