我正在建立一个简单的在线游戏,我希望用户在完成游戏时提示他们在Facebook上分享他们的分数。我真的不想过多地复杂化UI,理想情况下它希望它的工作方式类似于twitter的推文按钮,并且有一个预定义的(可编辑的)消息,如:
“我刚刚在mygame.com上获得了560分”
我希望将其发布到用户的Facebook墙上。
代码和用户最简单的选择是什么?我在php,mysql,jquery,javascript,ajax
工作答案 0 :(得分:0)
假设您手头有Facebook Javascript SDK,您可以构建一个链接到https://www.facebook.com/dialog/feed?app_id=393236134020452&link=<the url you want to share>&picture=<url of any picture you want to show in the users' status updates>&name=<title of the status update>&caption=<text of the status update>&redirect_uri=<url to redirect users upon completion of the sharing action>
的按钮,可能在新标签中。
如果你想看一下,我使用纯JS和JS SDK制作了类似的here。
答案 1 :(得分:0)
建议您使用Javascript SDK:https://developers.facebook.com/docs/reference/javascript/
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID - get one at https://developers.facebook.com/apps/
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here - Change fields below to match what you want to share and wrap it inside a function that you trigger on click
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
频道文件可以只是:
<script src="//connect.facebook.net/en_US/all.js"></script>
答案 2 :(得分:0)
$attachment = array(
'access_token' => $accessToken,
'message' => $text,
'name' => $appName,
'link' => $appLink,
'description' => "I have just scored 560 on mygame.com",
);
return $response = $facebook->api("/$fbid/feed", 'POST', $attachment);
其中$ facebook是Facebook API对象。你必须创建Facebook应用程序并允许在用户的墙上发布。