Facebook account delink or deauthorize facebook app and check status of linking from facebook app

12,764

Solution 1

Please note Facebook in the process of deprecating the REST API, and have adding equivalent support to the Graph API User object for "auth.revokeAuthorization" method.

//$this->facebook is facebook object
//$userid is of logged in user or can be written hardcoded.
For checking linked in or not by making api call.

        $user_id = $this->facebook->getUser();
        $result = $this->facebook->api(array(
                'method' => 'fql.query',
                'query' => "SELECT is_app_user FROM user WHERE uid=$user_id"
        ));
        $is_installed = $result[0]['is_app_user'];
        if($is_installed==1) {
            echo 'Linked';
        }
        else {
            echo 'Not Linked';
        }


For delinking or deauthorization the user by making app call:

        $user_id = $this->facebook->getUser();
        $access_token=$this->facebook->getAccessToken();
        $result = $this->facebook->api(array(
                'method' => 'auth.revokeAuthorization',
                'uid' =>$user_id,
                'access_token'=>$access_token
        ));

Solution 2

With the new Graph there is a documented way to deauthorize (I've tested it in the Graph API explorer and it works). Send an HTTP Delete command to "me/permissions" with a valid access token. Not only will it invalidate the access token, but it also removes the app from the user's list of auth apps. This requires the user to authorize the app again (going thru the permissions screens) to use it. Happy coding!

Solution 3

This can easily achieved with simple FQL query:

SELECT uid FROM user WHERE uid = {USER_ID_HERE} AND is_app_user = true

This will return uid of user if he is connected with app and nothing otherwise

Solution 4

Make an API call to /{USER_ID}/permissions with your App access token and it will show if that user has authorised your app

You can also check with the user's access token if you have one.

The response type will be something like this:

{
  "data": [
    {
      "installed": 1, 
      "bookmarked": 1
    }
  ] 
}

There'll be one entry there for each extended permission the user has granted your app and the installed line means they've installed your app

For a user who hasn't installed your app the response will be:

 {
   "data": [  
   ]
 }

You can also use FQL as Juicy Scripter suggests in another answer

Solution 5

Here's how to deauthorize your app using Facebook iOS SDK v4:

#import <FBSDKCoreKit/FBSDKCoreKit.h>

...

NSString *graphPath = [NSString stringWithFormat:@"/%@/permissions", [FBSDKAccessToken currentAccessToken].userID];
[[[FBSDKGraphRequest alloc] initWithGraphPath:graphPath parameters:nil HTTPMethod:@"DELETE"]
    startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if ( !error ) {
        NSLog(@"Facebook unlinked");
    }
}];
Share:
12,764
Somnath Muluk
Author by

Somnath Muluk

If you want my advice/help you can make request on Codementor. You can share your screen and get your problem fixed. If you are looking for Freelancers team for your Projects (Website Development/ Wordpress Development / Android Apps / Ios Apps), then we have 15+ people team who works on freelancing projects. Start conversation at email: [email protected]. I am having experience of 10+ years. My profiles: LinkedIn Carrers Twitter Member of Facebook Developer Heroes (Community made by Facebook)

Updated on June 05, 2022

Comments

  • Somnath Muluk
    Somnath Muluk almost 2 years

    My website application having feature login with Facebook login. And for which my app is present on Facebook. Login with facebook is working fine.

    But application have feature of linking and unlinking facebook account to Facebook app.

    • How to check FB account is linked with specific FB app or not?
    • And how to unlink FB account from specific FB app if linked (On that user's request )?

    ("Linked" means we select "Allow" to FB app on request)