问题
I need to access the user's locale, before requesting any permissions from them. This is normally available in getSignedRequest but that appears to be NULL when I view the application directly rather than from within a page tab. So it is NULL when I go to apps.facebook.com/myapp/ but it has the correct values when I view it through a page like www.facebook.com/pages/mypage/pageid?sk=appid. Is this a bug or expected behavior? Do I have to use a different method when I won't be accessing the app through a page?
回答1:
From what I remember, on Facebook, a signed request will only be available on the first page of your tab - eg. index.php.
From here, you'll need to store the retrieved values and access them from local storage or a session as you need them.
Also, if you look at the the application directly it won't be available at all. You have to look at it through Facebook for this method to be available. Unfortunately you'll have to request permissions first if you want this information outside of the page tab.
Good luck!
回答2:
use $_REQUEST["signed_request"] for signed request instead of using function
$dd = parse_signed_request($_REQUEST["signed_request"]);
// function to parse function parse_signed_request($signed_request) { list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
return $data;
}
function base64_url_decode($input)
{
return base64_decode(strtr($input, '-_', '+/'));
}
来源:https://stackoverflow.com/questions/9264581/getsignedrequest-is-null-when-not-on-a-tab-page