admin管理员组文章数量:1400134
I've been looking quite a lot for an actual example of how to implement asking for permissions with facebook login, but I couldn't find any. All I can find is the name of the permissions, advice on what to ask, but no examples.
The question is: Where and how can I ask for permissions using php or js? A bit of code would be very helpful. I am new to facebook developing and I've started reading all I can about facebook login and facebook api and trying to do a couple of small apps so I get used to how things work, but I am a bit stuck.
Edit I found this code, which seems to be what I've been looking for:
FB.login(function(response) {
// handle the response
}, {scope: 'email,publish_actions'})
I've been looking quite a lot for an actual example of how to implement asking for permissions with facebook login, but I couldn't find any. All I can find is the name of the permissions, advice on what to ask, but no examples.
The question is: Where and how can I ask for permissions using php or js? A bit of code would be very helpful. I am new to facebook developing and I've started reading all I can about facebook login and facebook api and trying to do a couple of small apps so I get used to how things work, but I am a bit stuck.
Edit I found this code, which seems to be what I've been looking for:
FB.login(function(response) {
// handle the response
}, {scope: 'email,publish_actions'})
Share
Improve this question
edited Mar 7, 2013 at 21:52
MihaiB
asked Mar 7, 2013 at 21:17
MihaiBMihaiB
1391 gold badge4 silver badges17 bronze badges
1 Answer
Reset to default 6You should start with Facebook PHP SDK , the key is to understand server-side login flow, as explained here, you can use this example as a start:
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOU_APP_SECRET',
));
// 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.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} 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" => "user_photos"));
}
?>
<!doctype html>
<html xmlns:fb="http://www.facebook./2008/fbml">
<head>
<title></title>
</head>
<body>
<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
<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./<?php echo $user; ?>/picture">
<h3>Your User Object (/me)</h3>
<pre><?php print_r($user_profile); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>
</body>
</html>
本文标签: phpFacebook request permissions exampleStack Overflow
版权声明:本文标题:php - Facebook request permissions example? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744236794a2596592.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论