Facebook SDK, How do I check if a user has accepte

2019-07-21 15:24发布

问题:

I've got to a point in my app where a user can login via the Facebook SDK. The app requests read and publish permissions. Is there a way to check if they have accepted the publish permissions before carrying on? The permission is "publish_actions". I tried doing Session.getPermissions(); but only the read permissions are listed there (basic_info, user_birthday, user_friends).

It seems like there is no way to check if the user accepted my publish permission, is there a possible workaround to this?

The reason I need to check for this is because the permissions can be revoked by the user at any time from their profile, so I can't have them login then revoke the permissions, otherwise that would defeat the purpose of asking for it.

Would really appreciate some help, thank you. Hopefully it's possible and not a Facebook restriction (Although I can sort of see why if it was).

回答1:

For your app, you can use any valid user access token, and make a call to /me/permissions, and it will return a list of permissions that the user has granted your app.

For more docs, see https://developers.facebook.com/docs/graph-api/reference/user/permissions/



回答2:

According to Facebook SDK v4+:

To get the list of permissions associated with the current access token, call:

AccessToken.getCurrentAccessToken().getPermissions();

To get the list of declined permissions, call:

AccessToken.getCurrentAccessToken().getDeclinedPermissions();


回答3:

I think the Best way to check for permission:

Facebook SDK 4.+ :

if (AccessToken.getCurrentAccessToken().getPermissions().contains("publish_actions")) { 
    //permission exists
}