[英]Facebook messaging API cURL PHP
我正在嘗試向自己發送一條消息(由於未發布,因此是頁面管理員)。 我已經在我的Facebook應用程序上設置了權限,並獲得了訪問令牌,但是我收到無法按以下方式向此ID發送消息:
object(stdClass)#21 (1) {
["error"]=>
object(stdClass)#20 (4) {
["message"]=>
string(59) "(#100) Parameter error: You cannot send messages to this id"
["type"]=>
string(14) "OAuthException"
["code"]=>
int(100)
["fbtrace_id"]=>
string(11) "Be4HuMv5xOZ"
}
}
這是我的代碼:
public function Sendfb()
{
$request = 'https://graph.facebook.com/v3.3/me/messages?access_token=xxx';
$body = array(
'messaging_type' => 'RESPONSE',
'recipient' => array('id' => 'xxx'),
'message' => array('text' => 'Hello Messaging world')
);
$body = json_encode($body);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($body))
);
$output = curl_exec($ch);
$output = json_decode($output);
curl_close($ch);
var_dump($output);
}
我還需要做其他事情嗎?
您只能“回復”郵件,但不能與Page發起對話。 否則,您將沒有任何可用的ID:
該ID必須是通過Messenger入口點或Messenger Webhooks檢索到的ID(例如,某人可能會在Messenger中發現您的公司並從那里開始對話。
這些ID是頁面范圍的ID(PSID)。 這意味着ID在給定頁面中是唯一的。
如果您具有現有的Facebook Login集成,則用戶ID是應用程序范圍的,並且不適用於Messenger平台。
來源: https : //developers.facebook.com/docs/messenger-platform/reference/send-api/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.