SOLVED: Permission Issues Regarding stream.publish - Post to Wall

Oct 22, 2009 at 3:25 AM

Hey All,

I am getting a permission error when I try to use stream.publish in a Facebook Connect implementation.  I must be missing something in regards to who can publish what, but my application is currently trying to publish from the logged in user to their own stream.  Please see code below:

        if (ConnectionAuthentication.isConnected())
        {
            facebook.Components.FacebookService fbService = new facebook.Components.FacebookService();
            fbService.API.ApplicationKey = ConnectionAuthentication.ApiKey;
            fbService.API.Secret = ConnectionAuthentication.SecretKey;
            fbService.API.SessionKey = ConnectionAuthentication.SessionKey;
            fbService.API.uid = ConnectionAuthentication.UserID;
            Trace.Write("Post To Wall UserId: " + fbService.API.uid.ToString());
            Trace.Write("Session Key: " + fbService.API.SessionKey);
            fbService.API.stream.publish("This is a facebook developer's toolkit message test.", null, null, fbService.API.uid.ToString(), Convert.ToInt32(fbService.API.uid));
        }

I am getting the correct uid and a session key value in my trace, but the permissions error is thrown on the next line.  I THINK the user is allowing the application (api key) to post to their wall.

Here is the error message I get in the trace:

Permissions error
  at facebook.API.ErrorCheck(String xml)
  at facebook.API.processResponse(WebResponse webResponse)
  at facebook.API.SendRequest(IDictionary`2 parameterDictionary, Boolean useSession)
  at facebook.stream.publish(String message, attachment attachment, IList`1 action_links, String target_id, Int32 uid)

I am a bit new to some of the more advanced toolkit features, outside of basic authentication.  Any help is greately appreciated.

Thanks,
Josh

 

 

 

 

 

Oct 22, 2009 at 5:08 AM

I stayed at this for a bit longer and was able to get this working successfully.  Here is the fix for others....

This was a permissions issue and the user needed to give publish_stream permissions in order for this to work.  I had to include the following control on my .aspx page:

<fb:prompt-permission perms="publish_stream"><font>Grant permission for status updates</font></fb:prompt-permission>

However, in order for this control to render, I also had to include this code in the .aspx too (right below the body tag):

 <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script> 
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script> 
<script type="text/javascript"> 
FB.init("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "/xd_receiver.aspx");   // Replace with your api key
</script>

At this point, the FB control rendered as expected and I was able to pop a FB window and have the user give the application permission.

After the user gave permission, the original code above ran like a charm.

I hope this helps others.

Thanks,
Josh

 

 

Oct 31, 2009 at 3:48 PM

Hi,

  I tried to do the same, but I'm still getting the same permissions error?, can you offer any advice?

  Perhaps, /xd_receiver.aspx is something specific to your application?

Regards

Fiach.

 

Oct 31, 2009 at 5:34 PM

You just need to be consistent in the name and location of your cross domain receiver file in order for the Facebook javascript stuff to work.  All of the facebook examples use xd_receiver.htm and there is a working copy of the contents you need to put in that file on the facebook developers documentation site.  

It can be nice to make it an aspx (or view in MVC) as then you can catch hits to it in the Visual Studio debugger and see what Facebook is sending to it.

Nov 25, 2009 at 2:58 AM

I would like to add to this discussion:

Adding that prompt-permission control works, but that is to grant full permissions, which many people don't want to do.  I have seen this come up (like in the D&D adventures fb app).

What I am curious is how to bring up the fb dialog I see in most apps that comes up per post.  Perhaps the only way to post programmatically behind the scenes is to get total permissions as described above?

 

Thanks,

  Phil