我仍在尝试让我的网站与 Facebook Connect 一起工作。我一直在使用指南 here .
以下代码是从本地主机运行的(我的应用 ID 和 secret ID 已被删除):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
define('YOUR_APP_ID', '**MY APP ID**');
define('YOUR_APP_SECRET', '**MY SECRET APP ID**');
$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
function get_facebook_cookie($app_id, $app_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $app_secret) != $args['sig']) {
return null;
}
return $args;
}
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?access_token=' .
$cookie['access_token']));
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<?php if ($cookie) { ?>
<li> Welcome <?= $user->name ?></li>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= **MY APP ID** ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</html>
但是当我尝试通过 WAMP 运行它时出现以下错误:
Notice: Undefined index: fbs_**MY APP ID** in C:\wamp\www\fbtest.php on line 12
Notice: Undefined index: sig in C:\wamp\www\fbtest.php on line 20
Warning: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in C:\wamp\www\fbtest.php on line 30
Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file-get-contents]: failed to open stream: Result too large in C:\wamp\www\fbtest.php on line 30
但是,我怀疑这可能是 WAMP 的问题。所以我把这段代码放在私有(private)服务器上,没有出现这样的错误......但是,当我尝试点击 Login Facebook 按钮时,它会打开一个新窗口,它只告诉我 发生错误。请稍后再试。
我不确定如何解决这个问题。
最佳答案
尝试检查您是否向 javascript 发送了正确的凭据。您的应用程序的 url 或 appId 似乎与您在应用程序编辑部分填写的不正确或相同。如果您在 Iframe 中运行,请发送此 header ,它真的很有帮助,您不会遇到其他问题。
Header('P3P: policyref="/p3p.xml", CP="IDC DSP COR IVAi IVDi OUR TST"');
使用 WAMP。一个问题是您在 file_get_contents 中不支持 https。错误来自实际服务器还是您也在那里更改了应用程序 ID?
如果你还有问题,我可以发给你一些小例子,你可以测试一下。
关于php - WAMP 与实时服务器 facebook 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377045/