I am trying to allow users to post stuff from my site to their wall on FB. Unfortunately, when I decorate the action method with the CanvasAuthorize or FacebookAuthorize attributes, the method does not get called. And when I don't, the Post("me/feed") call complains about the access token.
Apparently, I could do that in two ways: either send the signed_request object along with the AJAX call, or send the access_token after the user has been authorized. I'd rather do the second because I tried the first and I could not get it to work.
So anyway, I went ahead and got some code from the FB documentation but it did not work out for me. The problem is most likely because the AJAX call does not wait for the authorization process to complete (you can see my code
here). So what I want to do is once the user clicks on the button, in Javascript, it has to call the function which triggers the AJAX call, but first it has to check whether the user is logged in or not. If he is, I need to get the access_token from the session and pass it along with the AJAX call, otherwise, give the user the login popup, and once he has logged in, proceed with the AJAX call...
This could be helpful and much easier than what I have right now. But how do I check for the facebook session in Javascript?
EDIT: I tried
this but it did not work for me. When I click on the button for the first time, it redirects me to the FB login page and then returns me back to my website's home page. After that, all it does is redirect and then back to the home page right away. Nothing gets posted.