简体   繁体   中英

Connect with facebook using PHP SDK in codeigniter

Im implementing facebook's PHP SDK for authentication here . I've searched over net and found lots of tutorial on that. like Using Facebook PHP SDK 3 with CodeIgniter

i've modified base_facebook.php to return www.skillpaper.com/auth/fb_register in

$this->facebook->getLoginUrl()

when i click "Connect with Facebook" in login modal and facebook auth popup appears its successfully redirect to my given url. ie www.skillpaper.com/auth/fb_register

and my code is like in auth controller:

public function fb_register(){

        $userId = $this->facebook->getUser();
        if($userId != 0){
            // Get user's data and print it
            $user = $this->facebook->api('/me');
            var_dump($user);
        }else{ echo "No user";}
}

i'm getting "No user" every time! What am i missing? I don't want to use any JS API for this. any suggestion?

Thanks in advance.

Please Download the Facebook PHP SDK From https://developers.facebook.com/docs/reference/php/ Now Put src folder into application/controller folder. Call into controller any function like this :-

    require 'src/facebook.php';
    $appId = FBAPPID;
    $secretkey = FBSECRETKEY;

    $facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $secretkey,
    ));
    $fb['facebook']=$facebook;
    $facebook_user = $facebook->getUser();
    $fb['facebook_user']=$facebook_user;
    if ($facebook_user) {
  try {
    $user_profile = $facebook->api('/me');
    //$fb['logoutUrl'] = $facebook->getLogoutUrl();

  } catch (FacebookApiException $e) {
    error_log($e);
    $facebook_user = null;
    $this->load->view('Your Page');

  }
    }else {
        $data['loginUrl'] = $facebook->getLoginUrl(array(
        'scope'         => 'user_about_me,email,user_birthday,friends_birthday,publish_stream,manage_pages,offline_access'              
        ));
        $this->load->view('Your Page');
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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