facebook app in a page tab - How to get callback URL
I am a bit of a catch 22 situation here.
When you load your app into a tab and ask for permission you need to send with it a callback url.
The callback url is a bit of a mission because on a page http://www.facebook.com/pages/<PAEG NAME>/<PAGE ID>?sk=app_<APP ID>
the only way to get the <PAGE ID>
is to get it out of the signed request:
parse_signed_request($_REQUEST['signed_request'], $APPSecret)
which you can only do when the user has given permission. And you need the ID to be able to get the <PAGE NAME>
, which basically means I cannot construct the callback url...
Does anyone know of a better way or different 开发者_Go百科way to Ask for permissions immediately as the page loads and then reload the page?
It seems that you are a bit confused, here are some points:
Your callback (redirect) url should be something relative (or identical) to the Tab url you specify in the application settings. Something like:
http://www.example.com/canvas/tab/index.php
So no need for the page id.
- Even if the page id is not needed, you'll still receive it (even without authorization) in the
signed_request
!
Read the Facebook documentation related section carefully:
When a user selects your Page Tab, you will received the
signed_request
parameter with one additional parameter,page
. This parameter contains a JSON object with anid
(the page id of the current page),admin
(if the user is a admin of the page), andliked
(if the user has liked the page). As with a Canvas Page, you will not receive all the user information accessible to your app in thesigned_request
until the user authorizes your app.
So the thing that you'll not receive is the USER ID not the page id which is kind of obvious since the admin "allowed" the application.
Hope this will clear things out for you.
Use JavaScript SDK
http://developers.facebook.com/docs/reference/javascript/
And use this allow dialog
http://developers.facebook.com/docs/reference/javascript/FB.login/
This way you don't even need to refresh.
Also, you can get page_id in signed_request even without user allowing it. You're talking about user_id and oauth_token which won't get passed unless signed-in user doesn't allow your app.
精彩评论