small medium large xlarge

Generic-user-small
17 Mar 2010, 19:36
Jed S (16 posts)

I don’t know if I am duplicating a question that has already been answered but I will ask anyway. I have a facebook application which is set as an iframe. The application wouldn’t be using facebook connect; it will just be an iframe app within facebook. I have spent the past few days trying to make a popup dialog for publishing to the wall appear after an object is created.

Following various samples all over the internet I whipped up a publisher for my app.

I have the following in my publisher model:

  def twig_feed_template
    one_line_story_template "{*actor*} pondered on the qoute: {*twig*}"
  end
  
  def twig_feed(twig, facebook_session)
    send_as :user_action
    from facebook_session.user
    data :twig => twig.message
  end

And to call this I have in my controller:

def create
    @twig = current_user.twigs.build(params[:twig])
    respond_to do |format|
      if @twig.save
        flash[:user_action_to_publish]  = TwigPublisher.create_twig_feed(@twig, facebook_session)
        format.html { redirect_to twigs_path }
      else
        format.html { redirect_to twigs_path }
      end
    end
  end

And in my view:

    = fb_connect_javascript_tag
    = init_fb_connect "XFBML" do
      = fb_user_action(@user_action_to_publish) if @user_action_to_publish

However, after an object is created, no dialog for publishing to the wall appears. I tried looking through firebug, and it did generate the proper javascript. Here is the firebug output snippet when I execute the app in localhost:3000(outside facebook):

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
//<![CDATA[
             Element.observe(window,'load', function() {
                FB_RequireFeatures(["XFBML"], function() {
                  FB.init('my_api_key','/xd_receiver.html', {});
                  try {
FB.Connect.showFeedDialog("10150132627230531", {"twig":"ert"}, null, null, null, FB.RequireConnect.promptConnect, null, "", null);
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('FB.Connect.showFeedDialog(\"10150132627230531\", {\"twig\":\"ert\"}, null, null, null, FB.RequireConnect.promptConnect, null, \"\", null);'); throw e }

                });
              });

//]]>

The strange thing is, when the app is executed inside the facebook iframe, those two mentioned javascripts above are not there. So basically, what I want to do is publish to wall after a create event. Any help or if someone can point me in the right direction it would be greatly appreciated.

Head_pragsmall
18 Mar 2010, 11:55
Mike Mangino (543 posts)

You need to use the new stream publishing methods. user action publishing has been removed. I’m going to spend some time over the next week removing deprecated messaging.

Mike

Generic-user-small
18 Mar 2010, 13:23
Jed S (16 posts)

Thanks for the reply. What are the new stream publishing methods? Which facebooker methods could we use to publish to the wall? Or perhaps if it is not yet in facebooker I could help contribute in creating the new methods. Could you please point me in the proper direction? Again thanks a heap for any help :)

Head_pragsmall
18 Mar 2010, 13:50
Mike Mangino (543 posts)

I would use the profile publisher with send_as :publish_stream

http://facebooker.rubyforge.org/classes/Facebooker/Rails/Publisher.html

Mike

Generic-user-small
18 Mar 2010, 13:55
Jed S (16 posts)

Thanks! I will try that out.

Generic-user-small
18 Mar 2010, 14:58
Jed S (16 posts)

Ok I tried that and still no popup dialog. I followed your example in the fb_connect_example app. The only thing I changed in the code I posted at the beginning of the post is the publisher model: (I have registered it through the console after changing the template)

  def twig_feed(twig, facebook_session)
    send_as :publish_stream
    from facebook_session.user
    a = Facebooker::Attachment.new
    a.name = "#{facebook_session.user.name} twigged!"
    a.description = twig.message
    attachment a
  end

and in my view:

= fb_connect_javascript_tag
= init_fb_connect "XFBML" do
  = fb_connect_stream_publish(@user_action_to_publish) if @user_action_to_publish

I checked the javascript in firebug again and it is generated by the helper methods. Any thoughts on why the dialog is not appearing?

Head_pragsmall
18 Mar 2010, 15:44
Mike Mangino (543 posts)

Do iFrame apps use the FBConnect js? Do you get errors from firebug?

Generic-user-small
18 Mar 2010, 16:06
Jed S (16 posts)

Do you mean this javascript? If so, yes the app is able to render that. And also there are no errors in firebug <script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>

Head_pragsmall
18 Mar 2010, 17:01
Mike Mangino (543 posts)

Ugh. That’s annoying. I would double check all of the configuration, including the XD receiver file. If everything still looks okay, I would try filing a bug with Facebook. You can also post the question on the facebooker google group. More people there have IFrame app experience

Generic-user-small
18 Mar 2010, 17:17
Jed S (16 posts)

I tried doing this in the console:

TwigPublisher.deliver_twig_feed

and it throws an exception Facebooker::Session::PermissionError: The user hasn't authorized the application to perform this action

I have checked the application settings and “Publish recent activity to my wall” is enabled

Head_pragsmall
18 Mar 2010, 17:39
Mike Mangino (543 posts)

Did you grant the extended permission? TwigPublisher.create_twig_feed should still work, so the js version will typically work even without the extended permission.

Generic-user-small
18 Mar 2010, 18:23
Jed S (16 posts)

I believe I am confused with the extended permission stuff. How exactly do I grant it? I searched for it on Application and account settings and I can’t seem to find it

Head_pragsmall
18 Mar 2010, 18:45
Mike Mangino (543 posts)

You have to use fb:prompt-permission. That’s not necessary for the javascript solution though

Generic-user-small
18 Mar 2010, 19:02
Jed S (16 posts)

I have the extended permissions dialog appear with this:

<script type="text/javascript">
  // This pops up a facebook dialog
  // Include this partial when you want to bring up the dialog asking
  // the user to grant permanent permission to post to their wall
  // http://wiki.developers.facebook.com/index.php/API
  FB_RequireFeatures(["XFBML", "CanvasUtil"], function() {
    FB.Facebook.init("<%=Facebooker.api_key %>","public/xd_receiver.html");
    FB.XFBML.Host.autoParseDomTree = false;  //This is probably unnecessary
    FB.Facebook.apiClient.users_hasAppPermission('publish_stream',
function(result){
      if (result != 1)
      {
        // For more info, see
        // http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.sho...
        FB.Connect.showPermissionDialog("publish_stream", null, true);
      }
    } );
  });
</script>

However after clicking allow, I get

No route matches "/public/xd_receiver.html" with {:canvas=>false, :method=>:get}
Head_pragsmall
18 Mar 2010, 19:40
Mike Mangino (543 posts)

Aha! The xdreceiver path is wrong. It should be /xd_receiver.html

There is a helper you can use to do this: @init_fb_connect@. Also, make sure the xd_receiver file exists.

Generic-user-small
18 Mar 2010, 20:12
Jed S (16 posts)

Thanks Mike for your help. However, I still get the same error after after setting it to /xd_receiver.html I tried using the init_fb_connect helper but I have no luck in making it work. That maybe because I do not know how to use it. I just followed the sample on fb_connect_example and did the following:

<% init_fb_connect "XFBML", "CanvasUtil" do %>
	FB.XFBML.Host.autoParseDomTree = false;
	FB.Facebook.apiClient.users_hasAppPermission('publish_stream',
	function(result){
  if (result != 1)
  {
    FB.Connect.showPermissionDialog("publish_stream", null, true);
  }
	} );
<%end%>

It throws a compile error but after checking it many times I am quite sure the script is okay

Generic-user-small
19 Mar 2010, 02:08
Jed S (16 posts)

Okay so I was finally able to publish feeds to the wall in an iFrame app. What I did was I just went and crafted my own FBJS and it worked like a charm. Many thanks to Mike for replying to my questions. Cheers!

Generic-user-small
08 May 2010, 19:29
Artur (18 posts)

got the same error but for canvas application

facebook.stream.publish (0) Facebooker::Session::PermissionError: The user hasn’t authorized the application to perform this action:

should I put a code which is above somewhere on a page ?

btw, if User::publish_to Facebooker method, is still recomended or rather use Publisher model ?

ok, I’ve added something like this to before_filter

  def check_publish_stream_permission
    redirect_to facebook_session.permission_url("publish_stream") unless facebook_user.has_permission? "publish_stream"
  end

but what if I’l like to have it in dialog topup ?

Entires passed with publish stream may include images or html/fbml(?) how can I do this with facebooker ?

Generic-user-small
09 May 2010, 13:27
Artur (18 posts)

solved, with a code like this in application.fbml.erb

<% unless facebook_user.has_permission? "publish_stream" %>
  <% javascript_tag do %>
    function permission_ondone(result)
    {
       if(result == "") {
          document.setLocation('<%= fb_about_url %>');
       }
    }
    Facebook.showPermissionDialog('publish_stream', permission_ondone, false);
  <% end %>
<% end %>
Head_pragsmall
10 May 2010, 13:13
Mike Mangino (543 posts)

Great! Thanks for posting your answer here!

You must be logged in to comment