php 如何使用 Accessstoken 通过图形 API 向 Facebook 好友发送消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2943297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:13:08  来源:igfitidea点击:

how send message facebook friend through graph api using Accessstoken

phpfacebookfacebook-graph-apifacebook-messagesfacebook-friends

提问by JAMES

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

任何人都可以帮助我使用图形 API 向 Facebook 朋友发送消息。

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.

它不起作用。我手上有用户的访问令牌。只是我对发送过程感到困惑。

回答by Júlio Santos

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.

您无法使用 Facebook 应用程序发送消息。你曾经能够做到这一点,但(可预测的?)大量滥用导致此能力被撤销。

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

如果您的用户 Alice 为您提供了必要的扩展权限,您有以下选择:

  • 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
  • 代表爱丽丝发布到她的墙上
  • 给爱丽丝发送电子邮件
  • 代表 Alice 创建事件
    • 邀请鲍勃(不是您的用户)参加上述活动
  • 代表 Alice 向 Bob 发出请求/邀请
  • 从应用程序向 Alice 发出请求

回答by Bob Fanger

You could open the Send Dialogin 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/

有关详细选项,请参阅:https: //developers.facebook.com/docs/reference/dialogs/send/

回答by mwafi

$attachment =  array(

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

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

回答by user545351

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.

从技术上讲,您可以使用隐私设置进行提要或交叉提要帖子,该设置仅允许提要所有者查看帖子,但不会真正向某人发送消息。

回答by gkrdvl

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

回答by sulaiman sudirman

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.

您可以发送到他们的 Facebook 电子邮件。Facebook 电子邮件由个人资料昵称+'@facebook.com' 组成。该电子邮件将转到他们的 Facebook 收件箱消息。请注意,facebook 电子邮件不接受欺骗电子邮件。您将需要白标域或使用 SendGrid。

回答by Umangshu Chouhan

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

您将需要集成 xmpp chat 来回复消息和编写新消息。

回答by Plastic Sturgeon

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.

我看到这个帖子,发现不对。使用 javascriot api,您可以像这样发布到朋友的提要:在这个例子中,“friendID”是朋友的 FB 用户 ID。这个 api 调用需要“publish_stream”权限。

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.

所以这是通过 javasfcript SDK 实现的——PHP 方法必须类似。

回答by codercat

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];

回答by Nishchal Gautam

It seems like you want to send the message right into the receiver's primary inbox, there isn't any graph api for this, you need to use facebook xmpp chat api and send the message, however I have made a php class which is too easy to use, just some function calls and call to a send message function and message will be sent, its open source, check it out: facebook message api phpthe description says its a closed source but the comment says its a open source now, you can clone from github. It's a open source now.

似乎您想将消息直接发送到接收者的主收件箱中,没有任何图形 api,您需要使用 facebook xmpp chat api 并发送消息,但是我制作了一个 php 类,这太简单了使用,只是一些函数调用和调用发送消息函数和消息将被发送,它的开源,检查一下:facebook message api php描述说它是一个封闭源但评论说它现在是一个开源,你可以从github克隆。它现在是开源的。