dougua9328 2015-10-14 07:56
浏览 415

调用Facebook登录时出错

I'm new to web development, still a beginner.

I unsure on how to code for session calling the FaceBook if there any. However, I've added this at all pages which I want my facebook to be loaded. I believe it is the Facebook SDK. For example, I add this code in my register.php and login.php.

<body>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '<?php echo $config['appId']; ?>',
      xfbml      : true,
      version    : 'v2.4'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

I also added this in my config.php which I believe it is Config for FB Login.

$config = array();

However, every time I tried to click on the Facebook button in my login.php, there will be error such that

Fatal error: Call to a member function getLoginUrl() on a non-object in C:\wamp\www\sggrocer\loginFb.php on line 13

loginFB.php

<?php   
    session_start();
    include('ajax-helper/config.php');

    $_SESSION[$PROJECT_NAME . '-loginFb'] = true;
    unset($_SESSION[$PROJECT_NAME . '-logout']);

    $params = array(
      'scope' => 'email, user_birthday',
      'redirect_uri' => $base_url . "http://localhost/sggrocer/",
    );

    $loginUrl = $facebook->getLoginUrl($params);

    header('Location:' . $loginUrl);

?>

This is my login.php: https://jsfiddle.net/Snurainiyakob/V4u5X/872/

And the UI as follows: enter image description here

  • 写回答

1条回答 默认 最新

  • dragon012100 2015-10-14 08:23
    关注

    You miss to initialize your $facebook-object.

    Please take a look at the official documentation here. It offers nice examples to get started.

    $fb = new Facebook\Facebook([
      'app_id' => '1475470649428121',
      'app_secret' => '{your-app-secret}',
      'default_graph_version' => 'v2.4',
    ]);
    
    $helper = $fb->getRedirectLoginHelper();
    
    $permissions = ['email']; // Optional permissions
    $loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions);
    
    echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答