Facebook php api不验证用户?有人可以显示他们的工作登录码



facebook api开发新手…在PHP API的裂缝,只是试图让用户登录到facebook显示…到目前为止还没有成功……我尝试了以下不同的方法来获得fb用户的身份验证,但都无济于事。如何使用户ID读取?有人可以张贴只是这一小段他们的代码,以帮助我看到你是如何得到这个工作?谢谢!


<?php
require 'facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'zzzzzz',
  'secret' => 'yyyyyy',
));
// See if there is a user from a cookie
$user = $facebook->getUser();
?>

<?php
require 'facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
    'appId'  => 'zzzzzz',
    'secret' => 'xxxxxx',
  'scope'  => 'manage_pages,offline_access,publish_stream'
));
// Get User ID
$user = $facebook->getUser();

?>

<?php
require_once( 'lib/fb/src/facebook.php' );
$appId = 'zzzzzz';
$secret = 'yyyyyy';
$facebook = new Facebook( $appId, $secret );
// Get User ID
$user = $facebook->require_login();
?>

的样例代码从PHP SDK工作是完美的!

<pre>
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => '191149314281714',
  'secret' => '73b67bf1c825fa47efae70a46c18906b',
));
// 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;
  }
}
// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
?>
</pre>

您必须重定向用户到facebook登录页面进行身份验证。

$facebook = new Facebook(array(
  'appId'  => '...',
  'secret' => '...',
));
$user = $facebook->getUser();
    if ($user) {
         //user authenticate
        $logoutUrl = $facebook->getLogoutUrl();
        echo '<a href="$logoutUrl">loggout</a>';
         $friends =  $facebook->api('/me/'); //you profile details.. 
    } else {
      $loginUrl = $facebook->getLoginUrl();
       echo  '<a href="$loginUrl">Login with Facebook</a> to access this application.';
    }

您可以在新的PHP SDK文档中查看一些完整的示例;您可能会对API方法特别感兴趣。

相关内容

  • 没有找到相关文章

最新更新