Php Facebook API帮助

Php Facebook API帮助,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我该怎么办?这几乎只是从sdk中提供的示例中复制粘贴。我不明白人们怎么能用这个API构建任何东西??如何打开登录提示屏幕等?Facebook到底在哪里说了这些 <?php require 'fb_sdk/src/facebook.php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' =&g

我该怎么办?这几乎只是从sdk中提供的示例中复制粘贴。我不明白人们怎么能用这个API构建任何东西??如何打开登录提示屏幕等?Facebook到底在哪里说了这些

<?php

require 'fb_sdk/src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'APIID',
  'secret' => 'SECRET',
));

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Permissions requested from the user.
$par = array();
$par['scope'] = 'user_about_me, read_friendlists';

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl($par);
}

?>

评论中提到:

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl($par);
}
SDK会处理好的,你不用担心。 用户详细信息在$user\u profile中
做一个
echo';打印(用户档案);回声“,您将得到它。

您可以找到有关使用图形进行用户身份验证的信息

   die('<script>top.location.href = "' . $loginUrl . '"</script>');
使用
$loginUrl=$facebook->getLoginUrl($par)
变量
$loginUrl
将包含指向身份验证对话框的url。大多数开发人员要么将其作为链接呈现给用户,要么使用javascript执行重定向-例如:

<?php

require 'php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user_profile) { ?>
      Your user profile is 
      <pre>            
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre> 
    <?php } else { ?>
      <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script>               
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>', 
          cookie: true, 
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>

对于@Jollygood,回答得很好:不要为了它而考虑API。它可以帮助您使用应用程序。一旦你清楚你的应用程序将提供什么,与Facebook API的集成点就会清晰。以这个应用程序为例,您实现了您的应用程序想法,并得出结论,您需要Facebook上的用户全名、电子邮件、照片和好友,并相应地使用API。
 FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
       FB.logout(function(response) {
         console.log('Logged out.');
       });
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'user_about_me, read_friendlists'});