How to get the required require_login () function using the new PHP client library for Facebook?

Howdy. I was tasked with making the game on Facebook, but I'm new to Facebook development, so I'm just getting started. Sorry in advance if this is not a problem for people.

I am having problems with all the examples that I see on sites, and I continue to work with missing pages in the Facebook documentation when I try to read. I think this is because there is a new version of the PHP Client Library for Facebook, and everything that I find belongs to the old client.

For example, I see this code in many examples:

require 'facebook.php';
$facebook = new Facebook( array( 'appId' => '(id)', 'secret' => '(secret)' ) );
$facebook_account = $facebook->require_login();

... but there is no "require_login ()" in the client library provided in the facebook.php file.

From what I can say, it looks like Facebook just recently rolled out a new development system, but I don't see any code sample to handle this. The new library comes with an example.php file, but apparently it’s only intended to add Facebook login features to other sites (which I assume is what they mean by Facebook Connect sites) instead of launching applications on the Canvas page on Facebook itself.

, , Facebook, , , "", , . , , , . , , .

- PHP? require_login() , - , , - ? GitHub, , , , , , "facebook.php"...?

+5
4

require_login . .

function facebook_require_login($required_permissions = '')
{
  global $facebook; // NOTE GLOBAL FACEBOOK OBJECT, MUST ALREADY BE INSTANTIATED

  $user = $facebook->get_loggedin_user();
  $has_permissions = true;

  if ($required_permissions) {
    $facebook->require_frame();
    $permissions = array_map('trim', explode(',', $required_permissions));
    foreach ($permissions as $permission) {
      if (!in_array($permission, $facebook->ext_perms)) {
        $has_permissions = false;
        break;
      }
    }
  }

  if ($user && $has_permissions) return $user;

  $facebook->redirect(
    $facebook->get_login_url(Facebook::current_url(), $facebook->in_frame(),
                         $required_permissions));
}
+4

phpfour - php-sdk github.

- facebook.php require_login() ( , , )

public function require_login(){
  if ( !$this->getSession() ) {
    $url = $this->getLoginUrl( array(
       'canvas' => 1,
       'fbconnect' => 0
     ));
    echo "<script type='text/javascript'>top.location.href = '$url';</script>";
  }
 else
  return $this->getUser();
}
+1

php script git - wraper facebook api, , , fql , . , IRC , . , → api (\ me). script , , / , , . , ​​ ! , , . ( )

0

, PHP SDK. .

In short, you will need to go through an authenticated session, and then you can call functions to get the user ID of the logged in user. In this case, you will call the path "/ me" from the chart API.

0
source

All Articles