2012-11-08 27 views
-1

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

我附上了一张图片,在该图片中,我们可以看到SongPop的应用程序发布通知给我。我想做出这样的事情。我认为这个应用程序发布通知给他们的用户,我可以发布通知给特定用户吗?

notification from application

+2

尝试上市环节https://developers.facebook.com/docs/app尝试-notifications / –

回答

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); 
相关问题