我创建了一个小应用程序,基本上是一个测验应用程序(我即将在一个免费的网络托管网站上启动)。我想把它和Facebook结合起来。但主要有两个问题。
-
我希望该应用程序仅由我创建的特定组(它是一个封闭组)的成员的FB用户使用。
-
一旦测试结束,最终成绩将在群墙上公布。
您需要做的事情有很多。假设你正在使用FB JS SDK,你需要使用以下代码…
- 通过FB.login请求publish_stream和user_groups扩展权限
- 通过FB发布到群墙上。api,如…FB。api('/GROUP_ID/feed', 'post',{消息:'有人完成了测试'},function(response) {alert(response);});
使用FB JS SDK的部分示例(未实现组检查)…
<a onclick="postToGroupWall()">Post msg to group wall</a>
<script>
window.fbAsyncInit = function()
{
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true , // parse XFBML
oauth : true // Enable oauth authentication
});
FB.login(function(response)
{
if (response.authResponse)
{
alert('Logged in!');
// Check if user is in group using opengraph call (/me/groups) via FB.api
// Do that here...
}
else
{
alert('Not logged in - do something');
}
}, { scope : 'publish_stream,user_groups' });
};
window.postToGroupWall = function()
{
var opts = {
message : 'Yay I just completed the quiz',
name : '',
link : 'http://www....',
description : 'Description here',
picture : 'http://domain.com/pic.jpg'
};
FB.api('/GROUP_ID/feed', 'post', opts, function(response)
{
if (!response || response.error)
{
alert('Posting error occured');
}
else
{
alert('Success - Post ID: ' + response.id);
}
});
};
</script>
<!-- FACEBOOK -->
<div id="fb-root"></div>
<script>
(function() {
var e = document.createElement('script');
// replacing with an older version until FB fixes the cancel-login bug
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
//e.src = 'scripts/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<!-- END-OF-FACEBOOK -->
你需要做的一切与facebook(包括,但不限于,你已经解释的确切要求)可以实现使用facebook连接API。它非常全面,我无法解释你如何在这个答案中做整个事情。这是一个很好的开始:
http://developers.facebook.com/docs/reference/api/