how send message facebook friend through graph api using Accessstoken
Asked Answered
C

9

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.

Cthrine answered 31/5, 2010 at 11:49 Comment(2)
Do you have access token to john too ? The application need to have sufficient permission to be able to post anything to john's feedUnderdog
We are able to send answer by javascript. Check my answer.Mcswain
P
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
Psychopharmacology answered 31/10, 2010 at 0:24 Comment(4)
Note that you can't send email to Bob from Alice (a message from Alice to Bob appears to be the OP's goal)Suu
Well... one could play with the to field ;) But no, you can't. Hence it not being listed.Psychopharmacology
Here's the link saying you can't get friends' email addresses: developers.facebook.com/docs/reference/login/email-permissionsBanns
'Issue a request/invitation on behalf of Alice to Bob' how can someone do this from backend?Samira
F
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/

Fregoso answered 2/8, 2011 at 13:53 Comment(3)
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.Unstick
Is there a way to bypass the send dialog popup and send the message directly via url?Beforetime
could you have multiple userIds specified by app in the to field ?Sodom
T
5
$attachment =  array(

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

facebook->api('/'.$uesr_id.'/feed', 'POST', $attachment);
Tina answered 1/8, 2010 at 15:14 Comment(3)
This will post message on $uesr_id's wall.Mcswain
@SomnathMuluk This does not work anymore cause it is deprecated!Sunless
@Lomse: Yes... It's deprecated on Feb 2013.Mcswain
B
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.

Burmese answered 16/12, 2010 at 21:26 Comment(0)
A
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
Ashcraft answered 25/8, 2010 at 7:59 Comment(1)
links to documentation please?Hummer
H
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.

Hillinck answered 19/1, 2013 at 7:17 Comment(3)
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?Homogenesis
This didn't work for me :( Unfortunate, considering how easy it isIntended
Facebook has discontinued this since last February, it will forward to your real email instead. forbes.com/sites/kashmirhill/2014/02/25/…Hillinck
A
2

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

Aphotic answered 16/4, 2013 at 5:0 Comment(0)
N
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: 'https://mcmap.net/q/386600/-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.

Namedropper answered 14/8, 2012 at 21:57 Comment(0)
D
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];
Detoxify answered 28/11, 2012 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.