0

我正在尝试使用 facbook-php-sdk https://github.com/facebook/facebook-php-sdk来实现使用 facebook 的简单登录。该代码适用于某些人,但不适用于其他人。我正在尝试获取所有权限并在下一页上以 json 格式显示数据。

这是人们允许所有权限并转到下一页后的输出:- 错误图像

这是我正在使用的代码:-

<?php
require 'src/facebook.php';
set_time_limit(0);
ini_set('memory_limit','2560M');
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'cookie' => true,
));

// 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.
$limit = 1000;
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
    $statuses = $facebook->api("/me/statuses?limit=$limit");
    $albums = $facebook->api("/me/albums?limit=$limit");
    $likes = $facebook->api("/me/likes?limit=$limit");
    $activities = $facebook->api("/me/activities?limit=$limit");
    $posts = $facebook->api("/me/posts?limit=$limit");
    $events = $facebook->api("/me/events?limit=$limit");
    $notes = $facebook->api("/me/notes?limit=$limit");
    $checkins = $facebook->api("/me/checkins?limit=$limit");
    $friendlists = $facebook->api("/me/friendlists?limit=$limit");
    $friends = $facebook->api("/me/friends?limit=$limit");
    $groups = $facebook->api("/me/groups?limit=$limit");
    $interests = $facebook->api("/me/interests?limit=$limit");
    $photos = $facebook->api("/me/photos?limit=$limit");
  } 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(array(
    'scope' => 'email, user_actions.music, user_activities, user_events, user_hometown, user_location, user_questions, user_religion_politics, user_videos, publish_actions, user_actions.news, user_birthday, user_games_activity, user_interests, user_notes, user_relationship_details, user_status, user_website, user_about_me, user_actions.video, user_education_history, user_groups, user_likes, user_photos, user_relationships, user_subscriptions, user_work_history, friends_about_me, friends_actions.video, friends_education_history, friends_groups, friends_likes, friends_photos, friends_relationships, friends_subscriptions, friends_work_history, friends_actions.music, friends_activities, friends_events, friends_hometown, friends_location, friends_questions, friends_religion_politics, friends_videos, friends_actions.news, friends_birthday, friends_games_activity, friends_interests, friends_notes, friends_relationship_details, friends_status, friends_website, ads_management, export_stream, manage_notifications, photo_upload, read_friendlists, read_page_mailboxes, rsvp_event, status_update, xmpp_login, create_event, friends_online_presence, manage_pages, publish_checkins, read_insights, read_requests, share_item, user_online_presence, create_note, manage_friendlists, offline_access, publish_stream, read_mailbox, read_stream, sms, video_upload'
  ));
}

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>Approves it</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>Approves it</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

    <h3>PHP Session</h3>
    <pre><?php print_r($_SESSION); ?></pre>

    <?php if ($user): ?>
      <h3>You</h3>
      <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
      <?php print_r($user); ?>
      <h3>User Profile</h3>
      <pre><?php print_r(json_encode($user_profile)); ?></pre>
      <h3>Statuses</h3>
      <?php foreach ($statuses['data'] as $status): ?>
          <pre><?php print_r(json_encode($status)); ?></pre>
      <?php endforeach; ?>
      <h3>Albums</h3>
      <pre><?php print_r(json_encode($albums)); ?></pre>
      <h3>Likes</h3>
      <pre><?php print_r(json_encode($likes)); ?></pre>
      <h3>Activities</h3>
      <pre><?php print_r(json_encode($activities)); ?></pre>
      <h3>Posts</h3>
      <?php foreach ($posts['data'] as $post): ?>
          <pre><?php print_r(json_encode($post)); ?></pre>
      <?php endforeach; ?>
      <h3>Events</h3>
      <pre><?php print_r(json_encode($events)); ?></pre>
      <h3>Notes</h3>
      <pre><?php print_r(json_encode($notes)); ?></pre>
      <h3>Checkins</h3>
      <pre><?php print_r(json_encode($checkins)); ?></pre>
      <h3>Friend Lists</h3>
      <pre><?php print_r(json_encode($friendlists)); ?></pre>
      <h3>Friends</h3>
      <pre><?php print_r(json_encode($friends)); ?></pre>
      <h3>Groups</h3>
      <pre><?php print_r(json_encode($groups)); ?></pre>
      <h3>Interests</h3>
      <pre><?php print_r(json_encode($interests)); ?></pre>
      <h3>Photos</h3>
      <?php foreach ($photos['data'] as $photo): ?>
          <pre><?php print_r(json_encode($photo)); ?></pre>
      <?php endforeach; ?>
    <?php else: ?>
      <strong><em>You are not Connected. Please login with facebook.</em></strong>
    <?php endif ?>
  </body>
</html>

可以通过访问该站点来重现该错误:- http://approvesit-data.alphabetalabs.com/

有人可以帮我吗?

4

1 回答 1

1

解决方案:在为这个问题尝试了许多解决方案之后,这对我有用。

在 base_facebook.php 文件中,找到 makeRequest() 方法并检查以下行。

$opts = self::$CURL_OPTS;  

紧随其后,添加这一行

$opts[CURLOPT_SSL_VERIFYPEER] = false;  
于 2014-01-14T08:36:12.250 回答