1

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

0

1 Answer 1

1

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');
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for you comment. I'm already using that SDK in my project. I think im missing something in the redirect_url. Facebook does redirect in my given URL with a CODE=afa213131@w3423213133dsfasdfadf in the URL. But on that page(redirect URL) i can't get $facebook->getUser(); after he/she has given permission.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.