3

几天前我一直在使用 Facebook PHP SDK。我在这里的 Facebook Docs 中读到,如果你有他们的电话号码,可以向用户发送私人消息,但这似乎不起作用。

这是我的代码:

     $fb = new Facebook\Facebook([
      'app_id' => 'xxxxxxxxxxxxx',
      'app_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
      'default_graph_version' => 'v2.3',
      // . . .
      ]);
    $post = [
  'access_token' => $_SESSION['page_access_token'],
  'message'      =>  
  [
    'text' => 'Hello, wadup?!!!'
  ],
  'recipient' => [
    'id' => '+1(0)0000000000'
  ]
];

$response = $fb->post('https://graph.facebook.com/v2.6/me/messages?', $post, $_SESSION['page_access_token']);
print_r($response);

输出:

Facebook\FacebookResponse Object ( [httpStatusCode:protected] => 200 [headers:protected] => Array ( [x-page-usage] => {"call_count":1,"total_cputime":1,"total_time":1} [Strict-Transport-Security] => max-age=15552000; preload [x-fb-trace-id] => CQO0hjDHbf0 [x-fb-rev] => 3535263 [Expires] => Sat, 01 Jan 2000 00:00:00 GMT [Content-Type] => application/json; charset=UTF-8 [facebook-api-version] => v2.11 [Cache-Control] => private, no-cache, no-store, must-revalidate [Pragma] => no-cache [Access-Control-Allow-Origin] => * [Vary] => Accept-Encoding [X-FB-Debug] => WYq6KntFxQ/uTEK8B4tsvF+UfAXzsTtpm4yJcVxkrXkxTPo04yx/ITqLTe8Ho7k+tLhzC87eNojGjjgKXaGnIg== [Date] => Mon, 18 Dec 2017 09:43:11 GMT [Connection] => keep-alive [Content-Length] => 82 ) [body:protected] => {"id":"1157989877575188","url":"https:\/\/graph.facebook.com\/v2.6\/me\/messages"} [decodedBody:protected] => Array ( [id] => 1157989877575188 [url] => https://graph.facebook.com/v2.6/me/messages ) [request:protected] => Facebook\FacebookRequest Object ( [app:protected] => Facebook\FacebookApp Object ( [id:protected] => 1709050269133889 [secret:protected] => 1ceb6a6e1e4419f2799e699ebae2808e ) [accessToken:protected] => EAAYSX0Yx7EEBAH11ZAg7RWx60038nfYK1V1gOzqnu2NG0riV9DWiMRIJ9tZBfQwxqo92OaXx6uzhDZBn3xji8LXBP3mChJpbrCKpRLniUob9YlE1wZA3cnMSFIjA8eBjEaAUMJRfYvOBGfP7hIqMzNDU7fOPQOyXLFlPZAbdMZAQZDZD [method:protected] => POST [endpoint:protected] => https://graph.facebook.com/v2.6/me/messages [headers:protected] => Array ( [Content-Type] => application/x-www-form-urlencoded ) [params:protected] => Array ( [message] => Array ( [text] => Hello, wadup?!!! ) [recipient] => Array ( [id] => 100002192125690 ) ) [files:protected] => Array ( ) [eTag:protected] => [graphVersion:protected] => v2.3 ) [thrownException:protected] => )

我也尝试过根据文档使用收件人 Facebook ID,但它仍然无法正常工作。

4

1 回答 1

1

我知道这是一个老问题,但我到了这里,这可能有助于其他人的研究。

如果用户没有在 Messanger 应用程序上与机器人交互,Facebook 不允许机器人写信给用户。

您可以在此处找到可能的交互的详尽列表

于 2019-12-05T16:58:04.680 回答