I have changed the way my facebook page tab app asks for permissions.
I was using the javascript approach with FB Dialog and now I am using the redirect approach (in which the user is redirected to a FB page where the permissions are asked and then is redirected back to the facebook page tab).
The reason of the change is that I believe this approach will present
less bugs and issues than using the javascript dialogs.
When using the redirect approach, I need to specify the URL that the user will be redirected after providing permissions. I would like that this url was the url of the facebook page tab with the app installed.
When building the url of redirect, I know the current page_id and my app_id. With these info, I need to build the facebook page tab url, which should look like this:
https://www.facebook.com/pages/PAGE-SLUG/{#APP_ID}?sk=app_{#APP_ID}
The problem is that I don’t know what is the PAGE-SLUG. The tests I have run with the url above (using the PAGE-SLUG as anything) end up redirecting to the correct URL. However, knowing that Facebook is a very unstable platform, I would like to know it there is any better approach to building this redirect url.
EDIT: the above approach has a problem. The redirect loses the SSL protocol and uses the HTTP link when the facebook user doesn’t use SSL by default.
It’s very simple actually, you can call the Graph API with PHP like so:
the return value is a json array with “link” in it -> that’s the URL you are looking for 🙂
Example Return:
You can also query by the page name, if you know it, for example:
querying the Graph API with:
Will result in:
Edit:
A more clear explanation:
returned from the call.
Otherwise, the redirect_uri should be yourdomain.com/middle-page.php?page_id=XXX
you then call the Graph API again, but this time, you use the Access Token received
from Facebook. now you should have the real page url and you can add any additional
details you need (like ?sk_app=APP_ID)
According to Facebook own documentation, It’s not clear what happens if the user decided not no accept the application. I think the user will redirect back to the redirect_uri, which then you can check if you have “user_id” in the signed_request, but I’m not 100% sure… Creating a simple app demo and checking 🙂