1
votes

I have been using Graph API along with javascript facebook sdk to make posts on users wall. The code looks like this

function graphStreamPublish(){
                showLoader(true);

                FB.api('/me/feed', 'post', 
                    { 
                        message     : "Sample Message",
                        link        : 'link url',
                        picture     : 'image url',
                        name        : 'app name',
                        description : 'Test stuff'

                }, 
                function(response) {
                    showLoader(false);

                    if (!response || response.error) {
                        alert('Error occured');
                    } else {
                        alert('Post ID: ' + response.id);
                    }
                });
            }

Can this piece of code be used to post on users timeline as well or is there something else I need to do?

2
this code is working right now test your javascript codes here fbrell.com just you need to add facebook js sdk & config at first - Pooya Estakhri

2 Answers

0
votes

Years ago, you could use field TO with user id, nowadays you cant post to users timeline, but you can use TO field with an ID, for posting on groups, events or pages .

0
votes

The following code works. ( Notice the 'publish_actions' permission used at the end).

FB.login(function(response) {
    // handle the response

        if (response.status === 'connected') {// Logged into your app and Facebook.

                        FB.api('/me/feed', 'post', 
                            { 
                                message     : "Sample Message",
                                name        : 'app name',
                                description : 'Test stuff'

                            }, 
                            function(response) {

                                if (!response || response.error) {
                                    alert(response.error);
                                } else {
                                    alert('Post ID: ' + response.id);
                                }
                            });
          }


}, {scope: 'public_profile,email,publish_actions'} );