views:

1032

answers:

3

I want to programmatically publish messages to my site user's facebook page on their behalf, whenever certain events are triggered from my site. I'll have a cron that executes stream.publish when needed.

I am looking at stream.publish to accomplish this, which requires extended permission from the facebook user. Since the user will not be engaged in the publishing, how would I go about getting publish_stream extended permission from my user base? Can they do it while they are signing up on my site or if they provide me their username & password, can I do it for them?

http://wiki.developers.facebook.com/index.php/Using%5Fthe%5FOpen%5FStream%5FAPI#About%5Fthe%5Fpublish%5Fstream%5FPermission

+2  A: 

The only way to do this is via a permissions dialog. If you are using facebook connect check out FB.Connect.showPermissionsDialog otherwise you can easily include FB:prompt-permission in your fbml.

If you are using an iframe/facebook connect you can probably invoke FB.Connect.showPermissionsDialog without any user action (so the will see the dialog on page load). In the FBML case you will need to direct your user to click on the link that brings up the window.

Janek
A: 

You need to be looking in the Facebook Connect API. You do not want to collect their login or do this with a cron job. You will need to allow them to connect to your site with Facebook and prompt them for the stream publish permission. Then it is a simple javascript call with FB.Connect.streamPublish()

Facebook Connect page: http://wiki.developers.facebook.com/index.php/Facebook%5FConnect Basics: http://wiki.developers.facebook.com/index.php/Anatomy%5Fof%5Fa%5FFacebook%5FConnect%5FSite Feed Publish: http://wiki.developers.facebook.com/index.php/Implementing%5FFeed%5FPublishing%5Ffrom%5Fyour%5FWebsite%5For%5FApplication

Alternatively it is easier to create share links: http://wiki.developers.facebook.com/index.php/Connect/Using%5FFacebook%5FShare

Erik Nedwidek
A: 

You need to prompt for both the offline_access and stream_publish extended permissions. You can do this when they signup for your app. Maybe you have a settings page where the user turns on these notifications, and when they turn it on you can prompt for the extended permissions.

When you are granted offline_access by your user, their Facebook sessionkey will change and the expires value will switch to zero. This is known in Facebook circles as an "infinite sessionkey" You need to save this sessionkey for later use in your cron job. You can then call stream.publish using the infinite sessionkey as a parameter, and it will go through even though the user is not logged into your site or facebook at the time.

Pat James

related questions