Ram Kumar
Ram Kumar

Reputation: 590

posting on a friend's wall using graph API

Posting a message on friend's wall, graph API. i have the publish_stream extended permission of the user, who is using the application.

the code workds if i want to post sth on my wall.

is there any method to post on wall or send message to all the friends of a particular user??

please help thanks!!

following is the code, but it is not working.

 $friends = $facebook->api('/me/friends');
    foreach($friends['data'] as $friend){
            $friendsUserId = $friend['id'];
            echo $friendsUserId . "</br>";
            $result = $facebook->api('/$friendsUserId/feed', 'POST', array(                
                    message' => 'Test Message'                ));
            print_r($result);
        }

Upvotes: 4

Views: 12343

Answers (5)

Preethi
Preethi

Reputation: 11

$friends = $facebook->api('/me/friends');

foreach($friends['data'] as $friend) {
    $facebook->api('/$friend['id']/feed', 'post', array(
              'message' => 'just a test message',
              'link' => 'sample link.com',
              'name' => 'just a test name',
              'caption' => 'just a test caption',
              'description' => 'just a test description',
      ));

} Above code work for me tooooo Thanks for the post

Upvotes: 0

Mafia
Mafia

Reputation: 792

This would perhaps be the way to do it.. (Untested, but I use something similar for my app.)

$friends = $facebook->api('/me/friends');

    foreach($friends['data'] as $friend) {
        $facebook->api('/$friend['id']/feed', 'post', array(
                  'message' => 'just a test message',
                  'link' => 'http://site.com',
                  'name' => 'just a test name',
                  'caption' => 'just a test caption',
                  'description' => 'just a test description',
          ));

}

This is using the PHP API.

Upvotes: 6

Burgi
Burgi

Reputation: 1382

I just did a little testing, and having the permissions of the user, I could indeed post on the user's friends walls via the php api:

$facebook->api('/[FRIEND_ID]/feed', 'post', array(
          'message' => 'test message',
          'link' => 'http://google.com',
          'name' => 'test name',
          'caption' => 'test caption',
          'description' => 'test long description',
      ));

Upvotes: 5

Matt Foley
Matt Foley

Reputation: 911

Gubloo's answer is close.

Posting to a friend's wall is completely possible, but with one caveat, said friend must have also gone through the 'Permissions' dialogue at some point. Meaning, users of your application will be able to post to the wall's of other users of your application.

I'm going to give you the iPhone code, because I don't know php and imagine you'll get the gist. Just replace 'me' with the UID of whatever you are trying to post to, be a page, or a Friend's profile.

[_facebook requestWithGraphPath:@"/me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

I'm actually curious to know if this would give the user the ability to post on the wall of anyone who uses the application, and not just his friends.

Upvotes: 0

Gublooo
Gublooo

Reputation: 2618

The publish_stream permission only allows you to publish content on that particular users wall - you cannot post on the wall of all his friends.

Think about it this way - say you have not authorized an application to post anything on your facebook wall but just because one of your friends has given access to his wall - it automatically does not give the application access to publish on the wall of all his friends.

EDIT

Rahul, I tried yesterday night to login as myself and post a message on the wall of one of my friends through my app and surprisingly it worked. I was under the wrong impression that you could not do that. My apologies.

But I'm still not able to figure this out. Let me explain

1) I have my real facebook lets call it abc and a test facebook account xyz which I've added as my friend to abc
2) I login into my app using my abc faceboook account and publish a message on the wall of my friend xyz
3) Now I login to facebook.com as abc and it shows on my news feed the message that I published on xyz's wall. When I click on xyz's profile - the message shows up on his wall too. So far so good
4) Now I log out of facebook.com as abc and log back in as xyz. But now I dont see the message that was posted through the app on the wall of xyz.

I dont know if there is any kind of delay but I've waited 30 mins but still its not there. But it continues to show when I log in as abc.

I hope you understand what I'm trying to convey here. I've used the same piece of code like yours - so can you try the above scenarios and see if you experience something similar

Thanks

Upvotes: 3

Related Questions