views:

653

answers:

4

Hello,

I'm writing a callback function for the FB.Connect.showPermissionDialog() function which accepts permissions and an optional callback function.

It's supposed to be passed null if the user rejects the permissions dialog. But for some reason, my script always makes the post request even if the permissions request failed.

echo("FB.ensureInit (  function () { 
        FB.Connect.showPermissionDialog('email,offline_access',
        function(accepted) {
             if(accepted==null) {alert('failure');} else {
             $.post(\"http://www.domain.com/permissions.php\",
                   { username:$userID,mode:'accepted'});}    
        });
        });");

Not sure why it's not reading the value of accepted properly. Thanks for the help.

+1  A: 

Do with firebug:

console.log(accepted)

And see what you're getting back. Could be undefined, which according to your logic still passes.

Mike Robinson
+3  A: 

My first guess is that the Javascript null value is not actually being returned, and some other false-like value is being returned instead.

I'd try changing to this to test for all false-like values:

if (!accepted) {alert('failure')} else { 
...
Triptych
yea that worked great. says something about the facebook documentation though :P
Stanislav Palatnik
Yeah I checked out that documentation. Wasn't too great.
Triptych
+1  A: 

Maybe you should change your logic around:

echo("FB.ensureInit (  function () { 
        FB.Connect.showPermissionDialog('email,offline_access',
        function(accepted) {
             if(accepted !== null) {
             $.post(\"http://www.domain.com/permissions.php\",
                   { username:$userID,mode:'accepted'});}
             } else {alert('failure');}
        });
        });
   ");
Cory Larson
A: 

Even I am getting wrong response. I am trying for dialogues "email", "publish_stream", "user_birthday". If I do not allow any, it replies

accepted="user_birthday,user_religion_politics,user_relationships,user_relationship_details,user_hometown,user_location,user_likes,user_activities,user_interests,user_education_history,user_work_history,user_online_presence,user_website,user_groups,user_events,user_photos,user_videos,user_photo_video_tags,user_notes,user_about_me,user_status,friends_birthday,friends_religion_politics,friends_relationships,friends_relationship_details,friends_hometown,friends_location,friends_likes,friends_activities,friends_interests,friends_education_history,friends_work_history,friends_online_presence,friends_website,friends_groups,friends_events,friends_photos,friends_videos,friends_photo_video_tags,friends_notes,friends_about_me,friends_status"

If I allow all it replies accepted="publish_stream" only.

If I allow email only it replies accepted="email, ... etc..", which looks correct.

But, response is not seems as per expected in API documentation.

Alpesh Modi