Ansgar Helfrich
Ansgar Helfrich

Reputation: 61

Retrieving a facebookuserID

for my facebook quiz app I need to collect the facebookID of each participating user. My app is in an iframe of another App.

The "facebook-files" I put in the third party folder.

In my controller I invoke it like so:

  $this->ci->load->file(APPPATH.'/third_party/facebook.php');
  // Connect to Facebook API
  $this->facebook = new Facebook(array('appId' => $this->config->item('appkey'), 'secret' => $this->config->item('appsecret')));

It seems not possible to get the facebookID from a participant.

If try the this:

try {
    $user_id = $this->facebook->api('/me');
    //$signed_request = $_REQUEST["signed_request"];
    //$user_id = $signed_request['user_id'];
    //print_r( $user_id) ;
} catch ( FacebookApiException $e ) {
    error_log( $e );
    $user_id = 100;
}

the $user_id is 100. Can you get me start how to retrieve the right facebookid ? What would be the right way? Authentication process ?

Thanks in advance!

Ansgar

Upvotes: 0

Views: 82

Answers (1)

Simon Boudrias
Simon Boudrias

Reputation: 44649

to get the Facebook ID with PHP you need to use the method $fb->getUser() : https://developers.facebook.com/docs/reference/php/facebook-getUser/

Although, for this to work, the user need to connect into your app. This can be achieve in multiple way, but if you only do it with PHP you can use the getLoginUrl method to get the URL where the user will be asked to accept to login with your app (https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/). This is also achievable with JS SDK (which is my personal preferred way)

All documentation on Login Dialog can be found here: https://developers.facebook.com/docs/opengraph/authentication/

The key concept here is that the user is anonymous until you ask them to connect in your app.

Upvotes: 1

Related Questions