views:

3047

answers:

3

Hey guys, Now I know this question has been asked similarly a lot of times but I'm really struggling here.

Its a simple thing I need to do:

I would like to post a message onto a users wall saying "I scored 8/10 on objects game" then a URL

Thats it. I don't mind if facebook needs to authenticate and then post the message. and I really don't want to have to use the full API - as I don't want to handle user login details.

Is it possible using the new Graph API and javascript.

Uber thanks guys > this'll allow me to sleep tonight.

A: 

Yes, this is possible using the new Graph API and javascript, although I think your life will be much much easier if you have some server-side PHP to help you out.

First you'll have to authenticate using the publish stream extended permission, and then it's just a simple HTTP post request - see the "Publishing to Facebook" section in the Facebook Open Graph API. Note that you may have to register your application with Facebook first in order to get the Application ID necessary.

iffy
You're right it would be easier, but its not an option to allow server side programming on the clients server. They use a propriety framework.
Glycerine
Using the server-side code is only easier if you don't know what you're doing in Javascript. Use the right tool for the job.
Matchu
+3  A: 

You can use something like this to publish to a wall, the user will need to confirm before it get sent. Don't forget that you'll need use FB.init and include the JS SDK link.

 function fb_publish() {
     FB.ui(
       {
         method: 'stream.publish',
         message: 'Message here.',
         attachment: {
           name: 'Name here',
           caption: 'Caption here.',
           description: (
             'description here'
           ),
           href: 'url here'
         },
         action_links: [
           { text: 'Code', href: 'action url here' }
         ],
         user_prompt_message: 'Personal message here'
       },
       function(response) {
         if (response && response.post_id) {
           alert('Post was published.');
         } else {
           alert('Post was not published.');
         }
       }
     );  
  }
Soufiane Hassou
Disclaimer: haven't done a test-run of the code, but it looks right.
Matchu
I copied it from one of my working codes. The function is tested :)
Soufiane Hassou
F*cking love you guys. I'm going to give it a try tonight.
Glycerine
Well - Its done. another developer was on the case without me and finished it off - Thus - You get 100 points for being the dude who gave me code. Nice one Soufiane.
Glycerine
A: 

but it will post it on just one friend's wall. is it possible to post it on all of my friends' walls using api?

Saira Samdani