Talk:JS API M FB.Connect.showPermissionDialog
From Facebook Developer Wiki
Are there any plans to create a callback function for this method? I need to do an action following the request to gain permission and there appears to be no good way to tell when the permissions dialog is closed (accepted or denied). 15:07, 11 December 2008 (PST)
[update]
I wrote my own function to extend FB.Connect.showPermissionDialog in order to pass a callback which is called on completion. I started from the original code of the function, and merged it with the same callback handling logic found in FB.Connect.showFeedDialog.
Hope the Facebook team will consider put it on the release library, in order to let everybody be able to do actions on user permission dialog close.
Here the code, put in your own file, you need some basic JS understanding:
FB.Connect.showPermissionDialogCallback=function FB_Connect$showPermissionDialogCallback(permission, callback)
{
FB.Facebook.get_sessionState().waitUntilReady(
Delegate.create(null,function(result)
{
FB.IFrameUtil.CanvasUtilServer.run(true);
var singleton=FB.Connect._singleton;
var iframeDom=FB.XdComm.Server.singleton.createNamedHiddenIFrame('dialogContent','','fb_permission_iframe',null);
iframeDom.style.height='173px';
singleton._permissionDialog=new FB.UI.PopupDialog('Allow Extended Access?',iframeDom,true,false);
iframeDom.src=FBIntern.Utility.getFacebookUrl('www')+'connect/prompt_permission.php'+'?api_key='+FB.Facebook.apiKey+'&v='
+FB.Facebook.version
+'&next='+encodeURIComponent(singleton._permissionDialog._createCrossDomainClosingLink())
+'&cancel='+encodeURIComponent(singleton._permissionDialog._createCrossDomainClosingLink())
+'&channel_url='+encodeURIComponent(FB.XdComm.Server.singleton.get_receiverUrl())
+'&ext_perm='+permission;singleton._permissionDialog.show();
//ginomi: call the callback on closing event
singleton._permissionDialog.add_closing(
Delegate.create(null,function(closingResult)
{
singleton._permissionDialog=null;
if(callback){callback.invoke();}
})
);
//END modifications
})
);
}
Use at your own risk!!
Gino
