Skip to main content

The New Facebook Wall Publishing method Stream.publish

As recently facebook stopped supporting the feedstory publishing method to publish news on users wall and application developers from now on can't create feed templates. Facebook released a new methods to do so which are:

FB.Connect.streamPublish
stream.publish
Facebook.streamPublish

I figured out those new methods when I was building a new facebook application yesterday to predict who will win the soccer match between Egypt and Algeria tonight. It took me sometime to succeed in publishing the story on the wall, so I will share with you my experience and how I solved it out in Coldfusion.

As I build my applications using the work of Andrew Duckett who created the Facebook Rest Client Component, I will start from FacebookFBMLCLient.cfc file which contains the methods that communicates with facebook APIs.

As I have used one of the three methods above which sounded the best as I guess, this example will be based on stream.publish method.

The first step is to add the following method to the FacebookFBMLCLient.cfc file:

<cffunction name="publishStream" access="public" output="false" returntype="any" hint="Publish on Wall">

<cfargument name="session_key" type="string" required="true" hint="the session id of the logged in user">

<cfargument name="to_ids" type="string" required="true" hint="ids of all the friends user has chosen">

<cfargument name="message" type="string" required="true" hint="message">

<cfargument name="attachment" type="Any" required="true" hint="JSON Object">

<cfargument name="action_links" type="Any" required="true" hint="JSON Object">

<!--- local vars --->

<cfset var params = StructNew() />

<!--- the api call --->

<cfset params["session_key"] = arguments.session_key />

<!--- <cfset params["uids"] = arguments.to_ids />--->

<cfset params["message"] = arguments.message />

<cfset params["attachment"] = arguments.attachment />

<cfset params["action_links"] = arguments.action_links />

<!--- Invoke stream.publish API --->

<cfset sendNoteVar = xmlToStructParam('facebook.stream.Publish',params) />

<cfreturn sendNoteVar />


</cffunction>

The second step is that you need permission from the users of the application to grant the method permission to publish on their walls, this can be done in many ways see this link, in my application I ask the permission from users when they submit the form, which I believe is the best way. So if you are using a form in your application you may get the permission to publish on users wall by By including the promptpermission attribute in the form as below:

<
form name="Form" promptpermission="publish_stream" action="Action.cfm" method="post">


The third step is to call the publish stream method:

<
cfset attachment = '{"properties":{"Votes":{"text":"Members Voted: (#eg# Votes for EGYPT)(#al# Votes for ALGERIA) (No Winner #equ#)","href":"#faceBookPath#/#appName#","rating":"rate"}},"media": [{"type":"image","src":"http://www.abusalah.info/fbapps/fbapp3/imgs/Algeria.jpg","href":"http://apps.facebook.com/algeria-egypt/"}]}'>


<
cfset action_links = '[{"text":"Make Your Prediction","href":"#faceBookPath#/#appName#"}]'>


<
cfset #FBMLClient.publishStream(session.fb_session_key,session.fb_uid,answer1,attachment,action_links)#>



The attachment and action_links must be in JSON format, any simple format mistake will prevent the attachment or the action_links from being published, so you should be careful.

Please note that I didn't use all options that can be published using Stream.Publish method, you may add more options to your code see the list of media and other options here.

I believe thats all what you need to publish to wall using the new facebook api's, if you need any help or have any question please add a comment to the article.

Comments

  1. Nice post. Is there any chance you can add a link to download all the files you talk about? Thanks.

    ReplyDelete
  2. I will post a full tutorial with the code soon

    ReplyDelete
  3. Hi,
    Though it sounds good but bit tough to make it functional.If can you please provide a sample code regarding facebook wall publishing then it would be helpful for me.

    ReplyDelete
  4. I will upload a full example soon.

    ReplyDelete
  5. Would really like to see the full example. Great work Mustafa! /herve

    ReplyDelete
  6. Is there a way to post to many wall at the same time ?

    thanks

    ReplyDelete
  7. In your function call what is answer1? Also I cannot find the function 'xmlToStructParam' anywhere in FacebookRestClient.cfc - where are you getting it from? Trying to get this working. Thanks!

    ReplyDelete
  8. Answer1 is a variable that is to be published on the wall, it is a string variable.

    For the xmlToStructParam it is a coldfusion function.

    ReplyDelete
  9. Is there any chance you can add a link to download all the files you talk about? Thanks.

    ReplyDelete
  10. Please go to this post and copy the post and save them as advised, the link is:
    http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html

    ReplyDelete
  11. Is there a way to post to many wall at the same time ?

    ReplyDelete
  12. Yes you can, just go to this example:

    http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html

    now replace the code below:













    ----------------

    With the code below:







    Now this loop will publish to all ur friends walls.

    ReplyDelete
  13. it looks the code is not appearing in the comment contact me on mustafa at abusalah dot info

    ReplyDelete
  14. Hi Mustafa, I am trying to use your code but I am getting this error:
    Variable XMLTOSTRUCTPARAM is undefined.

    I just have the .cfm file and I am calling the function and passing the parameters...what am I doing wrong?

    ReplyDelete
  15. This is an old method by now, please see this post: http://blog.abusalah.info/2010/08/coldfusion-facebook-graph-api-publish.html

    This is 100% working and up to date.

    ReplyDelete

Post a Comment

Popular posts from this blog

Error: Write to Disk Access Denied - Troubleshooting - BitTorrent

I have downloaded Bit Torrent software and when trying to download I got an error after few seconds saying:

Error: Write to Disk Access Denied
Solving this problem is so simple:
Shut down BitTorrent program.
Go to Start and in the small search box on top of windows start button start typing Bittorrent and the program will show, right click with the mouse on the icon and Run as Administrator.
All ur problems are sorted out now and you can enjoy downloading...
Good Luck.

Importing SSL certs to Coldfusion Railo's keystore

If you are having the below error:
Railo 3.3.4.003 Error (javax.net.ssl.SSLHandshakeException)Messagesun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetCausejavax.net.ssl.SSLHandshakeException

This means you are trying to invoke an https webservice. to invoke an SSL webserver you need to import the certificate into Railo by using keytool command. Below are the steps on how to do this:

1- use fire fox to open the webservice and click on the padlock as shown on the below image:

2-Click on more information as below:
 3- Click on View Certificate as below:
4-Click on details as below:
 5- Now export the certificate and save it to your computer with .cer extension.

6- Search in railo folder for the keytool command location, in my case it was under railo\jdk\bin

7-  Search in railo folder for the cacerts location, in my case it was under railo\lib\railo-s…

Publish to Wordpress using JSON API plugin and Coldfusion

I was using Postie to automatically publish to wordpress blog. I was searching a better method of publishing using soap api or json api. I found an excellent json plugin that can be used to publish posts and comments to wordpress.
Please follow the below step by step, this code will let you publish automatically for froma different interface to wordpress rather than using postie or email.

Step one: Install json plugin, enable the plugin and then go to settings > JSON API and  activate post

Step two: you have to modify the file: yourwordpressdirectory/wp-content/plugins/json-api/controllers/post.php

Please replace the file content with the below or add the missing Authenticate method. This method is necessary to authenticate a user to wordpress to be able to post content without a valid session.


<?php /* Controller name: Posts Controller description: Data manipulation methods for posts */ classJSON_API_Posts_Controller{ publicfunctioncreate_post(){ global$json_api; $this->authenticate()…