Using Facebook's DeAuth Callback with the C# SDK
I'm trying to handle the DeAuth callback from Facebook in my .Net MVC3, so that I can retrieve the UserId and remove the user from my database.
I've created an actio开发者_运维百科n that writes to a log file (for debugging purposes) using code from this answer:
FacebookApp app = new FacebookApp();
string accessToken = app.Session.AccessToken;
long userId = app.UserId;
At first my code failed with app
being null
. I then tried to add the CanvasAuthorizeAttribute
to the Controller
, which didn't help much either. Is there some other attribute I should have added instead? Or is there something else I'm wrong?
Edit:
I'm using version 4.2.1 of the SDK.
Edit 2: Thanks to Pat I figured out that the following code does the job (without any attributes on the action or controller).
var app = new FacebookApp();
var userId = app.SignedRequest.UserId;
I do this by parsing the signed_request that comes when Facebook hits your DeAuth page:
string signedRequestValue = Request.Form["signed_request"];
var app = new FacebookApp();
var sig = app.ParseSignedRequest(signedRequestValue);
long userid = sig.UserId;
I am using a prior release of the SDK that I had to modify to make the ParseSignedRequest public (it was private), but I believe this is a public method in the latest release 4.2.1 that you are using.
精彩评论