- I'd like to simply display the users name and photo inside a flash app.
- I hope to do this only in the client without using any backend scripting.
- The ActionScript 3 SDK for Facebook Platform is under construction for the next few weeks to comply with new facebook requirements so I don't trust the current build to be useful.
We hav开发者_高级运维e searched and built tests for a week with no luck. I have a feeling the answer is either very simple or not possible.
Please help if you have a solution. Thanks
I think the current best practice is to get everything through the javascript SDK and pass those objects to your swf through the External Interface.
An example.. (make sure your swf's id is "flashObj")
Javascript code:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '<INSERT YOUR APP-ID>', status: false, cookie: true, xfbml: false});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function connectUser() {
FB.api('/me', function(response) {
var usrs = new Array();
usrs.push(response);
document.getElementById('flashObj').loadUser(usrs);
});
};
function requestLogin()
{
FB.login(function(response) {
if (response.session) {
if (response.perms) {
document.getElementById('flashObj').onLogin();
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'email,user_birthday'});
}
</script>
And then in AS3:
public function FBconnect():void {
ExternalInterface.addCallback("onLogin", onLogin);
ExternalInterface.call("requestLogin");
}
private function onLogin():void {
trace("FB LOGIN");
connectUser();
}
private function connectUser():void {
ExternalInterface.addCallback("loadUser", userCallback);
ExternalInterface.call("connectUser");
}
private function userCallback(data:Array):void {
trace("FB USER LOADED");
var userData:Object = data[0];
traceObject(userData);
_FBuser = new FBUser(userData.id);
_FBuser.firstName = userData.first_name;
_FBuser.lastName = userData.last_name;
var d:Date = new Date(String(userData.birthday));
_FBuser.birthDate = d;
_FBuser.gender = userData.gender;
_FBuser.email = userData.email;
dispatchEvent(new Event(Event.COMPLETE));
}
精彩评论