doushi7761 2011-06-16 18:53
浏览 119
已采纳

WAMP与Live服务器facebook连接

I'm still trying to get my site working with 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):

<!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:

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. 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.

I'm unsure how to resolve this either way.

  • 写回答

2条回答 默认 最新

  • drwghu6386 2011-06-16 21:41
    关注

    Try to check if you send correct credentials to the 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. If you are running in Iframe, send this header, it will really help and you will not hit another problems.

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

    With the WAMP. One problem is that you don't have support for https in file_get_contents. Is the error from the actual server or did you change the app id there as well?

    If you will have still the problems, I can send you some small examples, so you can test them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效