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>';
    
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名