我看过很多帖子都会遇到同样的错误,我尝试了很多应用设置和代码的组合。我在下面发布了我的应用设置和PHP代码。我对FB集成和PHP都很陌生,所以我可能会做一些明显愚蠢的事情。请帮忙告诉我它是什么!
FacebookSession::setDefaultApplication('*myappid*','*myappsecret*');
/**
* Returns the JSON encoded POST data, if any, as an object.
* @return Object|null
*/
// get the raw POST data
$rawData = file_get_contents("php://input");
// this returns null if not valid json
$JSONSignedRequest = parse_signed_request($rawData);
$SignedRequestArray = json_decode($JSONSignedRequest);
if($SignedRequestArray["oauth_token"]) {
echo 'You are already signed in!';
}
else {
if(isset($facebookLoginHtml)){
echo '<script language="javascript">';
echo "top.location.href='https://www.facebook.com/dialog/oauth?client_id=
{*myappID*}&redirect_uri={https://apps.facebook.com/myappnamespace/}&scope=publish_actions,
public_profile,user_friends,user_relationships,read_stream,publish_actions';";
echo '</script>';
}
}
function parse_signed_request($signed_request) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$secret = "*myappsecret*"; // Use your app secret here
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
// confirm the signature
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
StackOverflow不允许我将我的设置发布为图片或链接。大多数设置都是链接,所以我会尝试添加注释。