2

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)

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226

6 Answers6

10

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!

DMCS
  • 31,720
  • 14
  • 71
  • 104
  • How to send an HTTP Delete command to "me/permissions" with a valid access token? – Somnath Muluk Jan 03 '12 at 04:30
  • With the Facebook PHP SDK you can use `getAccessToken()` to make the URL: `/me/permissions?access_token=???` where `???` is the access token. You then need to use something like cURL to change the HTTP verb to DELETE and make that request. – Wildhoney Aug 22 '13 at 09:55
2

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
        ));
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
1

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");
    }
}];
devios1
  • 36,899
  • 45
  • 162
  • 260
1

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

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
1

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

Igy
  • 43,710
  • 8
  • 89
  • 115
  • You can make a DELETE request to /{USER_ID}/permissions with the app access token. this is the replacement for the old `auth.revokeAuthorization` call and will uninstall the app for that user – Igy Dec 30 '11 at 14:58
  • How to make this delete request. Please can you more elaborate on it? – Somnath Muluk Jan 02 '12 at 13:37
  • I'm not sure I can simplify that any further; if your SDK or code can't issue HTTP DELETE requestss, make a HTTP GET and include &method=delete as a GET paramater to 'fake' the DELETE request – Igy Jan 03 '12 at 09:36
-2

Through the Graph API, from the docs (thanks @DMCS):

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.

The olds REST API offers you auth.revokeAuthorization. You can read more about that on the auth.revokeAuthorization docs.

Be aware that the REST API will be deprecated in the future, although Facebook doesn't specify when exactly.

I am not aware of any way to get a list of apps a given user is connected to, or see any reason Facebook would make that available. To see if a user is connected to your app, the other answers here should provide you with a couple of ideas.

Julio Santos
  • 3,837
  • 2
  • 26
  • 47
  • 1
    Actually 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. – DMCS Dec 30 '11 at 15:01
  • Can you give some brief on it? I was trying to make call to that methods but failed to do so. Happy New Year. – Somnath Muluk Jan 01 '12 at 05:19
  • What do you need to know? It's an HTTP DELETE request, so get a valid access token and use cURL, like `curl -X DELETE "https://graph.facebook.com/PROFILE_ID/permissions?access_token=ACCESS_TOKEN"` – Julio Santos Jan 01 '12 at 14:32
  • BTW, It may be `GET` or `POST` requests as well with argument `method` equal to _delete_. – Juicy Scripter Jan 01 '12 at 18:30
  • @ Júlio Santos: How to use curl? Where to call that url? – Somnath Muluk Jan 02 '12 at 14:18
  • You use cURL for testing, it's a command line tool. I can't tell you how to use the PHP SDK for that since I never used it, although it would seem to be something along the lines of `$facebook->api('/PROFILE_ID/permissions', 'DELETE')`. At this point you need to do some googling, Stack Overflow is not your personal code machine. Check out http://developers.facebook.com/docs/reference/php/facebook-api/ – Julio Santos Jan 02 '12 at 22:47