如何从游戏请求中删除通知

时间:2011-08-30 12:06:01

标签: facebook facebook-graph-api facebook-php-sdk

我正在尝试删除应用程序加载时的应用程序通知。 因此,当我邀请我的朋友时,他会收到通知并请求“确定”,如果他点击它,那么它应该被删除。怎么样?我尝试了多种方法但没有成功。

$REQIDs=$_REQUEST['request_ids'];
$user_profile = $facebook->api('/me');
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXX&client_secret=XXXXXXX&grant_type=client_credentials";
$access_token = file_get_contents($token_url);
if($REQIDs){
$requests = explode(',',$REQIDs);
foreach($requests as $request_id){
$deleted = file_get_contents("https://graph.facebook.com/$request_id?$access_token&method=delete");
//not working ->> {"error":{"type":"GraphMethodException","message":"Unsupported delete request."}}
$deleted = file_get_contents("https://graph.facebook.com/".$user_profile['id']."_".$request_id."?".$access_token);
//not working ->> false
$deleted = $facebook->api($request_id."?".$access_token, "DELETE");
//not working ->> Fatal error: Uncaught GraphMethodException: Unsupported delete request.
}
}

任何人都有一些想法或看到错误?

2 个答案:

答案 0 :(得分:0)

当用户点击时,Facebook会将请求ID传递给您。然后,您可以调用此网址来删除请求:

https://graph.facebook.com/[request_ids]?access_token=[your_app_accessToken]&method=delete

请注意,如果您的应用程序向单个用户发送了一些请求,当他们单击FB标题菜单中的Notification Jewel时,您的代码将以逗号分隔的字符串发送所有请求ID。你需要围绕这个事实进行编码。我认为我说这个字符串中的id的顺序是最早的 - >最新删除最新的,你需要解析字符串中的最后一个id并删除它。

答案 1 :(得分:0)

在这里查看此主题>>> Topic。它完全解释了如何处理apprequests。

您的代码应如下所示:

$reqId = $_GET['request_ids']; // Get the id of the current request
$requests = $facebook->api('/me/apprequests/?request_ids='.$reqId);  //Get the request. Not sure if this is correct for specific request
$itemData = $requests[data][0][data];  //Get the data that was originally sent in the request

//Some code here to do whatever with the data

$delete_url = "https://graph.facebook.com/".$reqId."?access_token=".$token."&method=delete";

$result = file_get_contents($delete_url);  //Delete the request so there is only one there next time.

这应该做的工作。

祝你好运!