FB.api('/me/permissions', function (response) { //please note that we use data[0] if(response.data[0].publish_stream==1) { //Do some stuff such as post a photo to user wall } else { alert('You need to grant "Post on your behalf" permission in order to save to Facebook!'); } }It is easy, isn't it? There is my complete code for force user allow some permission for my app. It is not optimized yet, however it still run OK and meets my need.
FB.getLoginStatus(function(response) { if (response.status === 'connected') { FB.api('/me/permissions', function (response) { if(response.data[0].publish_stream==1) { FB.api('/me', function(response) { }); } else { FB.login(function(response) { FB.api('/me/permissions', function (response) { if(response.data[0].publish_stream==1) { //Do some stuff that need permissions } else { alert('You need to grant "Post on your behalf" permission in order to save to Facebook!'); } }); }, {scope:'publish_stream,user_photos,user_birthday,email'}); } }); } else if (response.status === 'not_authorized') { FB.login(function(response) { if (response.authResponse) { FB.api('/me/permissions', function (response) { if(response.data[0].publish_stream==1) { } else { alert('You need to grant "Post on your behalf" permission in order to save to Facebook!'); } }); } else { alert('You need to authorize the application before you do other action'); } }, { scope : 'publish_stream,user_photos,user_birthday,email' }); } });
Hung Nguyen
No comments:
Post a Comment