Actionscript 3 Facebook API limitations
I'm creating a Flash-based (AS3) Facebook Connect site using the Actionscript 3 API and though I've got basic FB Connect functionality in place in terms of allowing users to login correctly, I'm running into walls when trying to ask for certain extended permissions. I'm not positive, but it appears as though there are two fairly significant limitations to the AS3 API:
You must prompt for extended permissions separately from the initial login call. In other words, two modal dialogs, not one, are required. This seems to be because connecting is handled with instances of FacebookSessionUtil, while extended permissions requests are handled by instances of FacebookSessionUtil.Facebook.
It doesn't seem that there's a way to prompt users to allow their email address to be shared with your application. Though I've perused http://facebook-actionscript-api.googlecode.com/svn/release/current/docs/index.html quite thoroughly, it looks like the "EMAIL" permission there only prompts users to allow 开发者_JAVA百科your app to send them email via facebook, not to share their email address directly.
Are my assumptions wrong here? Would I be better off using JS and ExternalInterface for this sort of work? I'd rather not rebuild what's in place but if these limitations are real, it appears I'll have no other choice.
Any feedback or assistance would be greatly appreciated. Thanks!
1)You will have to override the onLogin
function in the DesktopSession
Class and add in your extended permission parameters.
2)It should work unless the change in the permissions model only allowed for proxied emails. Try querying it from the facebook user instance and see what you get.
Test it in the Developer console with the following api call in the console block
<button id="fb-login">Login & Permissions</button>
<script>
document.getElementById('fb-login').onclick = function() {
var cb = function(response) {
Log.info('FB.login callback', response);
if (response.session) {
Log.info('User logged in');
if (response.perms) {
Log.info('User granted permissions');
}
} else {
Log.info('User is logged out');
}
};
FB.login(cb, { perms: 'email' });
};
</script>
here's another way you can do it all directly in your AS3 (very handy)
this is a code snippet from a game i’m building on facebook that requires permissions at a certain point in the game.. it works well. (note you now have to specify a channel.html and oauth: true in your init call)
first make sure you have the most current version of the API (now at 1.7) (http://code.google.com/p/facebook-actionscript-api)
private function facebookInit():void // START THE SESSION…
{
Facebook.init(APP_ID, facebookInitHandler,{
appId: APP_ID,
status: true,
cookie: true,
xfmbl: true,
channelUrl: ‘http://yoursiteurl/channel.html',
oauth: true,
perms: “publish_stream,email”
});
}
private function facebookInitHandler(response:Object, fail:Object):void
{
if (response.accessToken)
{
userAccessToken = JSON.encode(response.accessToken);
facebookLoggedInWithToken = true;
loadProfileData();
} else {
facebookLoggedInWithToken = false;
}
}
private function loadProfileData():void
{
var request:String = ‘/me’;
var requestType:String = ‘GET’;
var params:Object = null;
Facebook.api(request, loadProfileDataHandler, params, requestType);
}
private function loadProfileDataHandler(response:Object, fail:Object):void
{
if (response) {
userID = response.id;
fullName = response.name;
firstName = response.first_name;
lastName = response.last_name;
userEmail = response.email;
userPicURL = ‘http://graph.facebook.com/‘ + userID + ‘/picture’;
}
}
enjoy!
精彩评论