2012-10-06 24 views
0

我到處搜索Web以找到我的問題的答案,但我沒有找到任何清晰和簡單的答案...如何使用PHP向用戶發送通知?我們認爲'用戶'已經安裝了FB App。如何使用PHP向用戶發送通知?

我嘗試這樣做的代碼:

$post_data = "access_token=".$facebook->getAccessToken()."&template=My message&href=http://google.com"; 

$curl = curl_init(); 

curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/".$user."/notifications/"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$page = curl_exec($curl); 
curl_close($curl); 

print($page); 

但我收到以下錯誤消息:{ 「錯誤」:{ 「消息」: 「(#15)該方法必須使用應用的access_token被稱爲」 ,「type」:「OAuthException」,「code」:15}} 我沒有使用正確的access_token? 感謝幫助我或者給我看的代碼... :)

回答

3

嘗試發送使用與訪問令牌格式通知作爲querystring

$post_data = "access_token=".$facebook->getAccessToken()."&template=My message&href=http://google.com"; 

$curl = curl_init(); 

curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/".$user."notifications?access_token= … &template= … &href= …"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$page = curl_exec($curl); 
curl_close($curl); 

print($page); 
+1

OK非常感謝,我認爲它的工作原理,但我沒有權限:「需要'manage_notifications'權限才能查詢用戶的通知。」 如何添加這個燙髮到我的應用程序? :) –

+0

manage_notifications權限。您可以從Developer應用的應用設置的關於 - >高級部分開啓「需要manage_notifications權限」遷移。此外,從週二晚上開始,您可以使用me標識符上的通知連接,通過Graph API訪問用戶的通知。我們將在啓動時更新文檔。 –

+0

我是法國人,「Paramètres> Advanced」部分中不存在「Require manage_notifications權限」。而「Paramètres> Autorisations」中的「用戶和朋友權限」字段完全不起作用! –