41

Can anyone help me to send message to facebook friends using graph api.

I tried

$response = $facebook->call_api("/me/feed", "post", "to=john","message=You have a Test message");

It's not working. I have the accesstoken of the user in my hand.only I am confused on sending process.

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
JAMES
  • 411
  • 1
  • 5
  • 4

9 Answers9

51

You can't send messages using a Facebook application. You used to be able to do that, but the (predictable?) colossal amount of abuse led to the revocation of this ability.

Provided Alice, your user, has given you the necessary extended permissions, you have the following options:

  • Post to Alice's wall on her behalf
  • Send email to Alice
  • Create events on behalf of Alice
    • invite Bob (not your user) to said events
  • Issue a request/invitation on behalf of Alice to Bob
  • Issue a request from the App to Alice
Julio Santos
  • 3,837
  • 2
  • 26
  • 47
29

You could open the Send Dialog in a popup.

 $parameters = array(
    'app_id' => $facebook->getAppId(),
    'to' => $facebookUserId,
    'link' => 'http://google.nl/',
    'redirect_uri' => 'http://my.app.url/callback'
 );
 $url = 'http://www.facebook.com/dialog/send?'.http_build_query($parameters);
 echo '<script type="text/javascript">window.open('.json_encode($url).', ...

For detailed options see: https://developers.facebook.com/docs/reference/dialogs/send/

Bob Fanger
  • 28,949
  • 7
  • 62
  • 78
  • Thanks a lot bob. I was exactly looking for this. This even helps in pre-populating message fields so it's so easy to send an invitation link to my app using this dialog. – qasimzee Aug 09 '11 at 09:40
  • 5
    Is there a way to bypass the send dialog popup and send the message directly via url? – CyberJunkie May 12 '12 at 19:04
  • could you have multiple userIds specified by app in the `to` field ? – Rajat Gupta Dec 12 '13 at 19:08
5
$attachment =  array(

    'access_token' => $access_token,
    'message'      => $msg,
    'name'         => $name,
    'link'         => $link,
    'description'  => $desc,
);

facebook->api('/'.$uesr_id.'/feed', 'POST', $attachment);
mwafi
  • 3,946
  • 8
  • 56
  • 83
4

Technically you can do feed or cross feed post with privacy settings that allows only the feed owner to see the post but its not really sending a message to a person.

user545351
  • 41
  • 2
2

You can send to their facebook email. Facebook email is consisting profile nickname+'@facebook.com'. The email will goes to their facebook inbox message. Note that facebook email does not accept spoofing email. You will need whitelabel domain or use SendGrid.

sulaiman sudirman
  • 1,826
  • 1
  • 24
  • 32
  • I know this was answered sometime back. But how do i get my hands on a white label domain? Do you know which criteria fb uses to determine spoofing? – Sajuna Fernando Oct 28 '13 at 18:34
  • This didn't work for me :( Unfortunate, considering how easy it is – user1349663 Jun 02 '14 at 12:02
  • Facebook has discontinued this since last February, it will forward to your real email instead. http://www.forbes.com/sites/kashmirhill/2014/02/25/that-email-address-facebook-made-up-for-you-will-now-forward-to-your-real-email/ – sulaiman sudirman Jun 02 '14 at 13:08
2

You will need to integrate xmpp chat to reply a message and to write a new message.

2
You can use
HTTP POST with
PATH
https://graph.facebook.com/friend_facebook_id/feed
PARAMETER
MESSAGE = your message
ACCESS_TOKEN = your oauth2 access token
gkrdvl
  • 960
  • 9
  • 20
0

I saw this post and noticed it was not right. Using the javascriot api you can post to a friend's feed like so: In this example "friendID" is the FB user ID of the friend. This api call requires the "publish_stream" permission.

FB.api('/'+friendID+'/feed', 'post', 
            {
                method: 'feed',
                message: messageText,
                name: 'write a title here',
                caption: 'Put a caption here.',
                description: 'Put your description here.',
                link: 'http://stackoverflow.com/questions/2943297/how-send-message-facebook-friend-through-graph-api-using-accessstoken',
                picture: 'link to the preview thumbnail',                   
            },
             function(response) {
              if (!response || response.error) {
                //alert('Error occured');
              } else {
                //alert('Post ID: ' + response.id);
              }
        });

So this does it with the javasfcript SDK- the PHP method must be similar.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
0

Instead of using the below code

    [facebook dialog:@"feed"
     andParams:params 
     andDelegate:self]; 

Use the following solution

[facebook requestWithGraphPath:@"me/feed"
   andParams:params
   andHttpMethod:@"POST"
   andDelegate:self];
codercat
  • 22,873
  • 9
  • 61
  • 85