how send message facebook friend through graph api using Accessstoken

97,272

Solution 1

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

Solution 2

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/

Solution 3

$attachment =  array(

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

facebook->api('/'.$uesr_id.'/feed', 'POST', $attachment);

Solution 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.

Solution 5

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

Share:
97,272
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • qasimzee
    qasimzee over 12 years
    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.
  • Somnath Muluk
    Somnath Muluk about 12 years
    This will post message on $uesr_id's wall.
  • Michael Mior
    Michael Mior about 12 years
    Note that you can't send email to Bob from Alice (a message from Alice to Bob appears to be the OP's goal)
  • Julio Santos
    Julio Santos about 12 years
    Well... one could play with the to field ;) But no, you can't. Hence it not being listed.
  • CyberJunkie
    CyberJunkie almost 12 years
    Is there a way to bypass the send dialog popup and send the message directly via url?
  • lomse
    lomse about 11 years
    @SomnathMuluk This does not work anymore cause it is deprecated!
  • Somnath Muluk
    Somnath Muluk about 11 years
    @Lomse: Yes... It's deprecated on Feb 2013.
  • John Erck
    John Erck almost 11 years
    Here's the link saying you can't get friends' email addresses: developers.facebook.com/docs/reference/login/email-permissio‌​ns
  • tusharmath
    tusharmath over 10 years
    links to documentation please?
  • Sajuna Fernando
    Sajuna Fernando over 10 years
    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?
  • Rajat Gupta
    Rajat Gupta over 10 years
    could you have multiple userIds specified by app in the to field ?
  • user1349663
    user1349663 almost 10 years
    This didn't work for me :( Unfortunate, considering how easy it is
  • sulaiman sudirman
    sulaiman sudirman almost 10 years
    Facebook has discontinued this since last February, it will forward to your real email instead. forbes.com/sites/kashmirhill/2014/02/25/…
  • lephleg
    lephleg over 6 years
    'Issue a request/invitation on behalf of Alice to Bob' how can someone do this from backend?