如果他们在我的网站上执行某项操作,我是否可以在给定的用户Facebook墙上发布消息?
基本上,我正在寻找一步一步的指导来实现这一点,因为我无法通过facebook文档弄清楚如何做到这一点.
Ash*_*ane 11
步骤1:
在facebook上设置一个新的应用程序.输入您的网站地址和域名等详细信息.记下api密钥,应用程序ID和应用程序密钥.您可以在此处设置新的Facebook应用程序.注意:为了能够访问Facebook开发人员仪表板,您需要成为经过验证的开发人员,即您应该使用您的手机号码或信用卡进行验证.
第2步:
设置身份验证方法以检查用户是否登录到Facebook以及是否存在facebook会话要求用户提供基本权限.您可以使用PHP SDK轻松完成此操作:
$fb_sdk_path = FACEBOOK_SDK_PATH;
require_once($fb_sdk_path);
//initialize FB object
$facebook = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'domain' => 'example.com'
));
//try to get session. if this fails then it means user is not logged into facebook
$session = $facebook->getSession();
if (!$session) {
//get facebook login url
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0
)
);
//put login url script to redirect to facebook login page (if you want to do this)
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
exit;
} else {
//try to get user details from session this will trigger the permissions dialog.
try {
$uid = $facebook->getUser();
} catch (FacebookApiException $e) {
}
}
Run Code Online (Sandbox Code Playgroud)
第3步:
使用Facebook Javascript FB.ui方法生成帖子表格.
<div id="fb-root"></div> <!-- don't forget to include this -->
<script src="http://connect.facebook.net/en_US/all.js"></script><!-- include fb js -->
<script type="text/javascript">
//initialize facebook
FB.init({
appId:'YOUR_APP_ID',
cookie:true,
status:true,
xfbml:true
});
//call this function on click or some other event
function post_to_profile() {
FB.ui({
method: 'feed',
name: 'title of the feed',
link: 'link on the title',
caption: 'caption to show below link, probably your domain name',
description: 'description',
picture:'picture to show',
message: 'default message. this can be edited by the user before posting'
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
这应该足以让它运作起来.
| 归档时间: |
|
| 查看次数: |
444 次 |
| 最近记录: |