我正在尝试使用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/
有人可以帮助我吗?
答案 0 :(得分:1)
解决方案:在为此问题尝试许多解决方案后,这对我有用。
在base_facebook.php文件中,找到makeRequest()方法并检查以下Line。
$opts = self::$CURL_OPTS;
紧接其后,添加此行
$opts[CURLOPT_SSL_VERIFYPEER] = false;