Update Facebook Status from Android Air Applications with Extended Permissions

Before I go into details about this exciting experiment with AS3 Facebook API and Android Air, I want to give credit to a few websites.

(The code that I used was from the first source, but used second source as a reference)
http://blog.flash-core.com/?p=233
http://blog.yoz.sk/2010/10/authorizing-facebook-applications-in-android/#more-2481

One of the coolest things about making games, is being able to post to social networks on how well you did. I’m in the middle of developing a Android Air/iOS application and since I’ve developed most of the functionality for the game, I wanted to implement this feature. After numerous hours of searching online and trying different workarounds, I finally made it work! For the purposes of testing, I used the Flash Web Application that I made for this experiment. One of the coolest things about making it work on the Android, you don’t need to change anything or create a new application in Facebook.

Below is snippets of the code that makes this feature work.

_view = new StageWebView();
_view.addEventListener(LocationChangeEvent.LOCATION_CHANGING, viewChangingHandler);
_view.addEventListener(LocationChangeEvent.LOCATION_CHANGE, viewChange);
_view.stage = stage;

_view.viewPort = _space;

var _sAppId:String = "";

var _sRedirectUri:String = "https://graph.facebook.com/oauth/authorize?client_id=_sAppId";

var _sScope:String = "publish_stream, create_event, rsvp_event, sms, offline_access, manage_pages, email, read_insights, read_stream, read_mailbox, ads_management, xmpp_login, user_about_me, user_activities, user_birthday, user_education_history, user_events, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationships, user_religion_politics, user_status, user_videos, user_website, user_work_history, email,publish_stream,offline_access,read_stream";

_view.loadURL("https://graph.facebook.com/oauth/authorize?client_id=_sAppId&scope=publish_stream, create_event, rsvp_event, sms, offline_access, manage_pages, email, read_insights, read_stream, read_mailbox, ads_management, xmpp_login, user_about_me, user_activities, user_birthday, user_education_history, user_events, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationships, user_religion_politics, user_status, user_videos, user_website, user_work_history, email,publish_stream,offline_access,read_stream&redirect_uri=http://www.griffinsdesigns.com/Facebook");

private function viewChangingHandler(event:LocationChangeEvent):void{
event.preventDefault();
_view.loadURL(event.location);

}

private function viewChange(event:LocationChangeEvent):void{
var _sRedirectUri:String = "https://graph.facebook.com/oauth/authorize?client_id=_sAppId";

var _sAccessToken:String;
if (_view.location.indexOf(_sRedirectUri) == 0 && _view.location.indexOf("access_token")!=-1){
_sAccessToken = "?"+_view.location.substring(_view.location.indexOf("access_token"), _view.location.indexOf("&expires_in"));
_view.stage = null;
}

}

Make sure you use loadURL, otherwise it will give you an error. The sources listed above, post, “load(new URLRequest( “. That does not work with the newest Air. If you look at my previous article about posting to Facebook, I mention a long URl that you want to redirect to, you want to use that URL as your URL that you will load.

What does this code do?

This code makes a web frame inside your Android Application and will show the Facebook Applicaton. If a new user goes to your application, the frame would show a login screen, like if they want to Facebook from a browser. After the user logs in, they would be sent to a page that lists the extended permissions (assuming you set the application to have extended permissons). Once the user clicks the allow button, they would be sent to the application.

I haven’t tested this on a Android Device. I only tested it by publishing it in Flash. The next thing I need to test is seeing if it would work when publishing it to a iOS application and test it on my iPad 2.

Facebook login screen inside Android Air Appliation

ExtendedPermissions in Android Air