Child pages
  • Post to wall
Skip to end of metadata
Go to start of metadata

Facebook integration

Apstrata allows you to easily interact and integrate with Facebook's APIs by providing you with a native server-side scripting object: the apsdb.social.facebook object. Using the method exposed by this facebook object, you can implement authentication scenarios using your end user's Facebook credentials and invoke any Facebook graph API. Apstrata also provides you with utility scripts that you can deploy to your Apstrata application back-end, which will even more facilitate the integration of your application with Facebook.

Back to the map       Next station: publish to wall

Example: let your players post messages on their wall from your app

Players are enjoying the mobile game app that you are developing so they need to post about it on their Facebook wall, notably they would like their friends to know about their score. Let us see how adding this feature in your application back-end is straightforward with Apstrata: you just create a simple script and invoke it from the client side of your app:

 

<script>
	<scriptACL>
		<execute>authenticated-users</execute> <!-- only users know by your Apstrata user directory can invoke this script -->
		<read>nobody</read>
		<write>nobody</write>
	</scriptACL>
	<code>
		<![CDATA[
		
		    // Retrieve the user's Facebook access token from the request
		    // Note: you should normally store this token in the user's profile in Apstrata
		    // and retrieve it from there
		    var facebookAuthToken = request.parameters["fbToken"];
		    var score = request.parameters["score"];
		    var message = request.parameters["message"];
   			// Create a post
			var post = {
		        "message": message
		    };	    
		    // The application id of the facebook application
    		var facebookAppKey = "EXAMPLE_501662753648720";    			
    		// The application secret of the facebook application
            var facebookAppSecret = "EXAMPLE_r6842a8850462815ge3df863fc78163d";            
            var url = "https://graph.facebook.com/me/feed";
			// Invoke the post graph API on Facebook to post the message
		    return apsdb.social.facebook.callApi(facebookAppKey, facebookAppSecret, facebookAuthToken, "POST", url, post);		
		]]>
	</code>
</script>
 
Try it!

Dig deeper

Related tutorials

  • No labels