-1

如何使用 facebook php sdk 作为应用程序向用户发布通知?

我附上了一张图片,在这张图片中,我们可以看到来自 SongPop 的应用程序向我发布了一条通知。我想做这样的东西。我认为这个应用程序向他们的用户发布通知,我可以向特定用户发布通知吗?

来自申请的通知

4

1 回答 1

0

您必须在您的应用配置中设置一个画布页面 url,然后尝试使用此代码

$url = "https://graph.facebook.com/$user_id/notifications";
$notification_message = 'My Example Notification Message';
$app_access_token = $app_id . '|' . $app_secret;
$attachment = array(
 'access_token' => $app_access_token, // access_token is a combination of the AppID & AppSecret combined
 'href' => '', // Link within your Facebook App to be displayed when a user click on the notification
 'template' => $notification_message, // Message to be displayed within the notification
   );
// set the target url
$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, true);  //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch); 
于 2012-11-08T12:38:53.697 回答