简体   繁体   中英

Can i get facebook friend list without login on facebook

I am useing facebook sdk and getting list of my friend but its getting when i login or i need to update url can i get list without need of login my sample code is this

<?php  include('src/facebook.php');
$facebook = new Facebook(array(
  'appId'  => '',
  'secret' => '',
  'cookie' => true,
));

$user = $facebook->getUser();
if ($user) {
  try {

    $user_profile = $facebook->api('/vikas.gautam.332/friends');

  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}


$vikas = $facebook->api('/vikas.gautam.332');
if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>

        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>

    <?php endif ?>



<?php if ($user){?>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">   
      <pre><?php print_r($user_profile); 
      ?></pre>
    <?php }?>
    <img src="https://graph.facebook.com/vikas.gautam.332/picture">
    <?php echo $vikas['name']; ?>

I believe you cannot get any data without access token and to get access token you need to login. Therefore, you still need to login. In short, it is not possible.


This is from Access Tokens - Facebook Developer

An access token is a random string that identifies a User, App or Page session and provides information about granted permissions. Access tokens are obtained via a number of methods, each of which are covered later in this document. The token also includes information about when the token will expire and which app generated the token. Because of privacy checks, the majority of API calls on Facebook need to include an access token. There are different types of access tokens to support these various cases:

  • User Access Token – This kind of access token is needed anytime the app calls an API to read, modify or write a specific person's Facebook data (their profile, photos etc.). This can be thought of as a limited and time bound permission that someone grants the app. In essence it is a temporary password that the app can use on behalf of the person. User access tokens are generally obtained via a login dialog and require a person to permit your app to obtain one .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM