用户id为(@[user_id])的Facebook应用程序通知模板不起作用


Facebook app notification template with user id ( @[user_id] ) not working

我无法让@[user_id]模板使用工作

$userid = <USER_ID>;
$friendId = <FRIEND_ID>; // This is a user who has accepted the app
$url = "https://graph.facebook.com/$userid/notifications";
$attachment =  array(   
                 'access_token'  => "$app_token",
                 'href' =>  "",
                 'template' => "@[" . $friendId . "] accepted challenge!"
               );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
//curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close ($ch);

$result返回"false"

$friendId是有效的应用程序用户,并且$app_token是"appid|appsecret"

如果我用"测试"之类的简单消息替换"模板",就可以正常工作

有什么想法吗?

您可能使用了错误的用户ID。为了确保您为朋友使用了合适的ID,请使用我/朋友和应用程序的有效用户访问令牌,并检查该ID是否在列表中,以及它是普通用户ID还是应用程序范围的ID。

此外,请确保您的应用程序未处于"开发人员模式",如果是,您需要将用户添加为测试人员或开发人员,以便测试应用程序。

我几分钟前已经测试过了,效果很好。

作为一个无关的问题,使用Facebook的PHP SDK不是更容易吗?

我希望它能有所帮助。


编辑:应用范围用户ID

Facebook于2014年4月推出了版本控制。在Facebook API V2中,我们介绍了应用范围用户ID,您可以在这里阅读更多信息:https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

基本上,如果您的FB应用程序是在2014年4月之后创建的,您将收到每个用户的唯一ID,该ID只能由您的应用程序使用。您必须使用此新的应用程序范围用户ID,而不是普通的Facebook用户ID。