登录 Facebook Canvas 应用的最佳方式是什么?我看到的所有教程都显示用户需要按下登录按钮,这看起来很奇怪,因为用户已经登录到 Facebook。我在 Facebook 上看到的其他应用程序显示“转到应用程序”按钮。使该对话框以扩展权限显示的过程是什么?oAuth Url 重定向是让我的应用访问用户信息的最佳方式吗?
问问题
1028 次
2 回答
0
本周第一次深入研究这些东西,所以我可能还没有以最好的方式做事,但这是我在沙盒中的做法:
$(window).load(function(){
login();
});
var login = function(){
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
get_fb_info();
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'user_about_me, friends_about_me, user_activities, friends_activities, user_birthday, friends_birthday, user_checkins, friends_checkins, user_education_history, friends_education_history, user_events, friends_events, user_groups, friends_groups, user_hometown, friends_hometown, user_interests, friends_interests, user_likes, friends_likes, user_location, friends_location, user_notes, friends_notes, user_photos, friends_photos, user_questions, friends_questions, user_relationships, friends_relationships, user_relationship_details, friends_relationship_details, user_religion_politics, friends_religion_politics, user_status, friends_status, user_subscriptions, friends_subscriptions, user_videos, friends_videos, user_website, friends_website, user_work_history, friends_work_history, email, read_friendlists, read_insights, read_mailbox, read_requests, read_stream, xmpp_login, ads_management, create_event, manage_friendlists, manage_notifications, user_online_presence, friends_online_presence, publish_checkins, publish_stream, rsvp_event, publish_actions, user_actions.music, friends_actions.music, user_actions.news, friends_actions.news, user_actions.video, friends_actions.video, user_actions:ssiz-three, friends_actions:ssiz-three, user_games_activity, friends_games_activity, manage_pages'});
}
我也很想听听这样做的“最佳”方法是什么。我也玩过,fb:login-button
但由于某种原因,我无法让它正常工作。
<fb:login-button show-faces="true" width="200" max-rows="1" scope="user_about_me...">
</fb:login-button>
于 2012-10-11T19:06:10.087 回答
0
我去了 PHP 路线,它似乎工作得很好。
$user = null; //facebook user uid
try{
include_once 'fb-php/src/facebook.php';
}
catch(Exception $o){
echo '<pre>';
print_r($o);
echo '</pre>';
}
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => 'YOUR APP ID',
'secret' => 'YOUR SECRET ID',
'cookie' => true,
));
//Facebook Authentication part
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,publish_stream,user_photos'
)
);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
//you should use error_log($e); instead of printing the info on browser
d($e); // d is a debug function defined at the end of this file
$user = null;
}
}
if (!$user) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
于 2012-10-11T21:57:19.890 回答