Search code examples
asp.netfacebookfacebook-graph-apiasp.net-identityclaims-based-identity

Check if user has my Facebook app installed


My website uses a Facebook application which sends notifications to its users.

On one of my pages the user can subscribe or unsubscribe (depending on whether or not he is subscribed).

Therefore I want to check if the user is using my app. How can I do that? I guess I could do the following to see if the app can access the data:

FacebookClient c = new FacebookClient(accessTokenClaim.Value);
c.AppId = MYAPPID;
c.AppSecret = MYAPPSECRET;
dynamic access = c.Get("/me/permissions");
if(access != null)
{
//has access
}

The one thing I don't like about this, however, is the fact that I have to use an access token to see if the user has the app installed.

I would prefer not to use access tokens since they tend to expire.

In my database I store the Facebook userIds of all my website users. Therefore it would be ideal if I could do something like the following:

/get?appinstalled&userid=USERID

What would be the best way to go about this?


Solution

  • To get the current user ID - to compare it with your DB - you will have to access FB graph API using an access token. So I think there is no way to find any info about the user without using FB access tokens. Edit: And do not worry about the expiration of the token, FB SDK will handle that for you. i.e. it will refresh automatically by the SDK. Here:

    Facebook's official SDKs manage the lifetime of tokens for you. When using iOS, Android or our JavaScript SDK, the SDK will handle making sure that tokens are refreshed before they expire.

    And

    Access tokens on the web often have a lifetime of about two hours, but will automatically be refreshed when required. If you want to use access tokens for longer-lived web apps, especially server side, you need to generate a long-lived token. A long-lived token generally lasts about 60 days.