[英]WAMP vs. Live server facebook connect
我仍然試圖讓我的網站使用Facebook Connect。 我一直在這里使用指南。
以下代碼從localhost運行( 我的應用程序ID和機密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的一個問題。 所以我把這些代碼放在私人服務器上並且沒有像這樣的錯誤......但是,當我嘗試單擊Login Facebook按鈕時,它會打開一個新窗口,它只會告訴我An error occurred. Please try again later.
An error occurred. Please try again later.
我不確定如何解決這個問題。
嘗試檢查您是否向javascript發送了正確的憑據。 它看起來像您的應用程序的url或appId與您在應用程序編輯部分填寫的不正確或相同。 如果你在Iframe中運行,發送這個標題,它將真的有幫助,你不會遇到另一個問題。
Header('P3P: policyref="/p3p.xml", CP="IDC DSP COR IVAi IVDi OUR TST"');
隨着WAMP。 一個問題是您在file_get_contents中不支持https。 是來自實際服務器的錯誤還是您在那里更改了應用程序ID?
如果您仍然遇到問題,我可以向您發送一些小例子,以便您可以測試它們。
即使您修復了https問題,Facebook Connect也無法在localhost中運行。 該腳本需要從您注冊Facebook應用程序的域中執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.