Creating a Facebook App Tab for Admins
I need to pass in user information (ie: userID, email address) from my portal into a Facebook app so that their profile shows on their Facebook tab when they grant access to use the application.
So 开发者_高级运维far, I decided to create an admin landing page/dashboard on Facebook, so that they can enter their email and password. I can then retrieve their userID to add to the Facebook tab, and it will load all of their information.
Right now, I need Facebook to know that I am passing in that value, and load it to the users Facebook Like page.
I am not sure if this is the proper method to use, or where I should begin.
If I understand your question correctly you want to know a general pattern for admin pages in Facebook apps.
What I usually do is identify whether or not the person viewing your page is an admin, and if so output a secure link to your editing page, which would then connect via Facebook and verify the user again before showing whatever forms you need to perform the administration tasks.
To determine if a user is an admin of the page: When you parse the signed request data, you should see a page.admin value. If you don't get any signed request data you can safely assume the user isn't an admin. You can use the PHP SDK to parse the signed request data or write your own stuff. I wrote my own library because I found the PHP SDK a bit hard to use. https://bitbucket.org/tlack/xfb
Once you know if they are an admin, output a link to your admin page. On that page do the typical FB Connect stuff with the JS SDK. Here's a little example I use in my Domain Trip Facebook app to request and store an offline access token that I use to manipulate the page later:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({
appId : '<?= $app_id; ?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true // enable OAuth 2.0
});
function login() {
var callback = function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/<?= $_REQUEST['id']; ?>?fields=access_token',
function(response) {
if (response.access_token) {
document.location = 'edit_permission.php?id=<?= $_REQUEST['id']; ?>&at='+response.access_token;
} else {
alert("Could not get permission to access page. Please contact help@domaintrip.com");
}
}
);
} else {
document.location = '<?= get_my_url(); ?>&f=1';
}
};
FB.login(callback, {scope: 'offline_access,manage_pages'});
}
</script>
<p>
We need permission to interact with your Facebook page.
</p>
<p>
<button onclick="login(); return false;">Login Now</a>
</p>
If you want to get really fancy, you could have the admin editing UI in the main page itself, unfolding when a button is clicked.
精彩评论