Facebook API SDK revoke access

2019-01-07 15:43发布

问题:

How can I allow a user to revoke access to my application using their API service, SDK. http://developers.facebook.com/docs/sdks/

Looking at the documentation I can't find anything about revoking the access.

回答1:

in the graph API for the user object you can issue an HTTP DELETE request to /PROFILE_ID/permissions to revoke authorization for an app.

from the official documentation (developers.facebook.com/docs/reference/api/user/):

You can de-authorize an application or revoke a specific extended permissions on behalf of a user by issuing an HTTP DELETE request to PROFILE_ID/permissions with a user access_token for that app.

Parameter Description Type Required permission The permission you wish to revoke. If you don't specify a permission then this will de-authorize the application completely. string no You get the following result.

Description Type True if the delete succeeded and error otherwise. boolean



回答2:

For the FB JavaScript SDK:

FB.api('/me/permissions', 'delete', function(response) {
    console.log(response); // true
});


回答3:

For anyone who would find this helpful, I was losing sleep and wrecking my brain for days trying to get this to work;

FB.api('/me/permissions', 'DELETE', function(response) {
    if (response == true) {
        window.top.location = 'logout-facebook.php';
    } else {
        alert('Error revoking app');
    }
});

I finally got this to work when I observed that the "response" being returned was not a boolean but a JSON object.

The JSON object being returned was either;

{
    success: "true"
}

OR

{
    success: "false"
}

Following that, the correct code was;

FB.api('/me/permissions', 'DELETE', function(response) {
    if (response.success == true) {
        window.top.location = 'logout-facebook.php';
    } else {
        alert('Error revoking app');
    }
});   

Hope this helps someone!



回答4:

With PHP SDK V 5

$DeletePermsUser = $fb->delete('/{user-id}/permissions/',[],$access_token);