I am new to this but we have created a new Android Native App using Air for Android in Flash CS 5.5. We have a working App and want to on the last screen, add a "Share to Facebook" button that will share the user's results to their Facebook wall / timeline. I have searched and searched but all I can find is either written in Java, not Actionscript 3, or is to update a status directly from the app. We only want to send a predefined snippet (User Results) from our app. Can someone please point me in the right direction??
Asked
Active
Viewed 1,810 times
2
-
One caveat to my answer below. My most recent experience of working with the API is in a web-based scenario. The SDK should be the same across web and mobile, and ought to abstract away any differences, but you may find you need to tweak the sample code somewhat for an AIR mobile app. – Jude Fisher Aug 22 '12 at 07:51
1 Answers
0
There's an API for this, with variants for AIR desktop, AIR mobile, and web applications. It began life being officially supported by both Facebook and Adobe, although I'm not sure if it still is:
http://code.google.com/p/facebook-actionscript-api/
There is plenty of documentation on how to use it. You need to create an app on facebook, just so you can identify yourself properly. Add the facebook developers app to your FB account and then see here:
https://developers.facebook.com/
The basics of a share to wall call will look something like this:
import com.facebook.graph.data.FacebookAuthResponse;
import com.facebook.graph.Facebook;
function initializeFacebook()
{
Facebook.init("YOUR APP ID", onFacebookInit);
}
var interval:int = -1;
function onFacebookInit(success:Object, fail:Object):void
{
if (success)
{
post();
}
else
{
var opts:Object = { scope:"publish_stream" };
Facebook.login(null, opts);
// In theory you should get a post back when logged in.
// In practice this often fails, and it's better to poll for an access token.
interval = setInterval(pollForLoggedIn, 500);
}
}
function pollForLoggedIn():void
{
if (Facebook.getAuthResponse().accessToken)
{
clearInterval(interval);
post();
}
}
function post():void
{
var auth:FacebookAuthResponse = Facebook.getAuthResponse();
var token:String = auth.accessToken;
var user:String = auth.uid;
var values:Object =
{
access_token: token,
name: "TITLE OF YOUR POST",
picture: "OPTIONAL THUMBNAIL PATH",
link:"OPTIONAL LINK",
description: "OPTIONAL APP DESCRIPTION",
message: "BODY OF POST"
};
Facebook.api("/" + user + "/feed", handleSubmitFeed, values, URLRequestMethod.POST);
}
function handleSubmitFeed(success:Object, fail:Object):void
{
// Done.
}

Jude Fisher
- 11,138
- 7
- 48
- 91