简体   繁体   English

WAMP与Live服务器facebook连接

[英]WAMP vs. Live server facebook connect

I'm still trying to get my site working with Facebook Connect. 我仍然试图让我的网站使用Facebook Connect。 I've been using the guide here . 我一直在这里使用指南。

The following code is run from localhost ( My app ID and secret ID have been removed ): 以下代码从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>

But gives me the following errors when I try to run it via WAMP: 但是当我尝试通过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

However, I suspected this might be a problem with WAMP. 但是,我怀疑这可能是WAMP的一个问题。 So I put this code live on a private server and got no errors like this... However, when I try to click the Login Facebook button, it opens a new window where it only tells me An error occurred. Please try again later. 所以我把这些代码放在私人服务器上并且没有像这样的错误......但是,当我尝试单击Login Facebook按钮时,它会打开一个新窗口,它只会告诉我An error occurred. Please try again later. An error occurred. Please try again later.

I'm unsure how to resolve this either way. 我不确定如何解决这个问题。

Try to check if you send correct credentials to the javascript. 尝试检查您是否向javascript发送了正确的凭据。 It look like the url of you application or the appId is not correct or same as you filled in in the applications edit section. 它看起来像您的应用程序的url或appId与您在应用程序编辑部分填写的不正确或相同。 If you are running in Iframe, send this header, it will really help and you will not hit another problems. 如果你在Iframe中运行,发送这个标题,它将真的有帮助,你不会遇到另一个问题。

Header('P3P: policyref="/p3p.xml", CP="IDC DSP COR IVAi IVDi OUR TST"');

With the WAMP. 随着WAMP。 One problem is that you don't have support for https in file_get_contents. 一个问题是您在file_get_contents中不支持https。 Is the error from the actual server or did you change the app id there as well? 是来自实际服务器的错误还是您在那里更改了应用程序ID?

If you will have still the problems, I can send you some small examples, so you can test them. 如果您仍然遇到问题,我可以向您发送一些小例子,以便您可以测试它们。

Even if you fix the https problem, Facebook Connect does not work from localhost. 即使您修复了https问题,Facebook Connect也无法在localhost中运行。 The script needs to be executed from the domain where you have your Facebook app registered. 该脚本需要从您注册Facebook应用程序的域中执行。

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

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