几天前我一直在使用Facebook PHP SDK。我已经在Facebook文档here中读到,如果您有他们的电话号码,可以向用户发送私信,但这似乎不起作用。
这是我的代码:
$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,但它仍然不起作用。
答案 0 :(得分:1)
我知道这是一个古老的问题,但是我来到这里,这可能会对其他人的研究有所帮助。
如果用户这样做,Facebook不允许机器人给用户写信 不能与Messanger应用上的机器人进行互动。
您可以找到可能互动的详尽清单here