简体   繁体   English

配置我的php.ini以运行Facebook php sdk

[英]Configure my php.ini for running Facebook php sdk

I am having problems with using the Facebooks php sdk. 我在使用Facebooks php sdk时遇到问题。 When printing the 打印时

$facebook->getSignedRequest() the print doesn't show any 'page' or 'user' values. $ facebook-> getSignedRequest()打印不显示任何“页面”或“用户”值。

I also tryed to print the $_REQUEST['signed_request'] and all I get is 我也尝试打印$ _REQUEST ['signed_request'],我得到的只是

Notice: Undefined index: signed_request 注意:未定义的索引:signed_request

Could it be some settings in my php.ini file that I've missed to do? 可能是我错过的php.ini文件中的某些设置吗?

Thanks for the help! 谢谢您的帮助!

This is only going to possibly solve half the issue, but remember $_REQUEST['signed_request'] not $_REQUEST('signed_request'); 这只会解决一半的问题,但请记住,$ _REQUEST ['signed_request']不是$ _REQUEST('signed_request');

EDIT: Ignore the last part as you mentioned, here is your answer: 编辑:忽略您提到的最后一部分,这是您的答案:

You are getting variables just not the ones you want. 您得到的只是变量,而不是您想要的变量。 It is returning a signed request, and you need to decrypt the request using your private key. 它返回一个签名的请求,您需要使用私钥解密该请求。 Heres how: 这是如何做:

function parse_signed_request($signed_request, $secret) {
  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);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check sig
  $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, '-_', '+/'));
}

Pass the signed request and your app secret into that and it will return your array. 将签名的请求和您的应用程序秘密传递给该请求,它将返回您的数组。 Im sure there is a way to do it with the Facebook SDK but im not not sure as I don't use it. 我确定可以使用Facebook SDK来实现此目的,但是我不确定,因为我不使用它。

More Info: https://developers.facebook.com/docs/authentication/signed_request/ 更多信息: https : //developers.facebook.com/docs/authentication/signed_request/

Goodluck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM