2013-04-04 30 views
0

我想用facbook-php-sdk https://github.com/facebook/facebook-php-sdk來實現一個簡單的facebook登錄。該代碼適用於某些人,但不適用於其他人。我試圖獲得所有的權限,並在下一頁以json格式顯示數據。facebook php sdk登錄錯誤: - 你沒有連接

這件事是人後允許所有權限,並進入下一個頁面的輸出: - Error Image

這是我使用的代碼: -

<?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/

有人可以幫我在這裏嗎?

回答

1

解決方案:在嘗試解決此問題的許多解決方案後,此工作適用於我。

在base_facebook.php文件中,找到makeRequest()方法並檢查以下Line。

$opts = self::$CURL_OPTS; 

緊隨其後,加入這一行

$opts[CURLOPT_SSL_VERIFYPEER] = false; 
+0

有可能成爲一種有用的someone.I無法驗證,如果因爲我不再在這個問題上工作的正確的解決方案。 – Divyanshu 2014-01-14 09:33:41