Integrating standalone php application in Facebook
I have created a small application , basically a quiz application ( I am about to launch that in a free web hosting website). I want to integrate that with Facebook. But there are mainly 2 issues.
I want the application to be used only by FB users who are member of a particular group (Its a closed group) which i created.
As soon as the quiz is over , the final score should be posted in the group wall.
PS: By integrate i mean , They can only begin the test when t开发者_StackOverflowhey signup using Facebook. Any other ideas are welcomed.
There are quite a few things you'll need to do. Assuming you're using the FB JS SDK, you'll need to use the following...
- Request the publish_stream and user_groups extended permissions via FB.login
- Post to the group wall via FB.api, eg... FB.api('/GROUP_ID/feed', 'post', { message: 'yay someone completed the quiz' }, function(response) { alert(response); });
Partial example using FB JS SDK (group checking unimplemented)...
<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 -->
Everything you need to do with facebook (including, but not limited to, the exact requirements you have explained)can be achieved using Facebook Connect API. It is very comprehensive and I can't explain how you would do the whole thing in this answer. This is a good place to start:
http://developers.facebook.com/docs/reference/api/
精彩评论