Publish media to wall using facebook Graph API

Facebook Graph API has been for a while now but in the past we were developing one of the facebook application for our client on php/mysql platform using yii framework. There was one requirement from the client to publish the media file(video / flash) on the friend’s wall so that it can be played on user’s wall. The main challenge with facebook application development is vague/obsolete documentation on the facebook wiki. After throughly investigation, we found two ways to publish media on friend’s wall.

1. Using Javascript SDK
2. Using Graph API

We can use facebook’s javascript api to publish media of friend’s wall like :

// Include facebook javascript by including http://connect.facebook.net/en_US/all.js
// Initialize facebook session
FB.init({
		appId  : ' getAppId();?>', // application Id
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true  // parse XFBML
	});
function publishStream(targetId, name, link, picture, source, userName,message) {
FB.ui(
        {
        	 method: 'feed',
        	 to: targetId,
                 name: name,
                 link: link,
                 picture: picture,
                 source:  source, // The URL of a media file (e.g., a SWF or video file) attached to this post
                 caption: 'Shared by '+userName,
                 actions:  {name: 'Try App', link: link},
                 message: message

        },
        function(response){
		     if (response && response.post_id) {
		      alert('Post was published.');
		     } else {
		       alert('Post was not published.');
		     }
        });
    }

Second way is to use Graph API:

http://www.facebook.com/dialog/feed?app_id=app_id&link=link&picture=picture &caption=caption&name=name&source=source &message=message&redirect_uri=response

We assume that you have already worked on facebook api. We would like to answer your questions.

Leave a Comment

Scroll to Top