Knowing how to share content from your app
In this tutorial you will learn how to share content from your app in users Facebook wall. for sharing to work, you don’t have to necessarily login your users or ask any permissions from them. you will setup the content to be shared and the Facebook SDK will open a dialog over your app where user can see and share the content. When sharing is completed, user will be redirected to your app again.
Facebook SDK supports three models of sharing.
- sharing an URL
- sharing a local photo planned to be supported on future versions
- sharing a local video planned to be supported on future versions
So, before seeing the actual codes to initialize a share activity on your app, you need to know how sharing works on Facebook SDK. the general rule is that you will first need to create a sharing model. after you initialize a new sharing model instance, you will setup its properties and then call the FB.share method to finish the job. The ANE will take care of the rest and will notify you of how the results went.
// when working with the FB ANE, you always need to initialize it with your fb app ID first
FB.getInstance("00000000000000"); // you need to call this only once when your app starts.
// now, initialize a new sharing model
var shareModel:ShareLink = new ShareLink();
// setup its properties based on the model you are targetting
shareModel.contentTitle = "title!";
shareModel.contentURL = "http://myappsnippet.com";
shareModel.imageURL = "http://myappsnippet.com/wp-content/uploads/2015/07/bundle-Jul-2015-adobe-air-extension_preview.jpg";
shareModel.contentDescription = "description!";
// and finally pass it to the ANE. results will be dispatched to function you specify (onSharingResult)
function onSharingResult($status:String, $msg:String):void
$status will be one of the following:
if it is "FBEvent.SHARING_ERROR", then $msg will explain the error reason
NOTICE: if you need to make sure that the sharing has been really cone successfully by your users, you need to have logged in your users. otherwise, the sharing results will always be FBEvent.SHARING_DONE even if the user cancels the sharing dialog! I know, it really sucks but that’s the Facebook logic and they say this is supposed to work this way