开发者

How to delete a notification from a game request

I am trying to delete an application notification on application load. So when I invite my friend he gets a notification and requests "ok" and if he clicks on it then it should be deleted. How? I have tried multiple ways but haven't succeeded.

$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.
}
}

Anyone have some ideas or see the error?


Take a look at this topic here >>> Topic. It explains pretty fully how to handle apprequests.

Your code should look like this:

$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.

This is supposed to do the work.

Good luck!


Facebook will pass you the request ids when your user clicks through. You can then make a call to this url to delete the request:

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

Note that if your application has sent a few requests to a single user, when they click the Notification Jewel in their FB header menu, your code will be sent all request ids in a comma separated string. You will need to code around this fact. I think I'm right in saying that the order of the ids in this string is oldest -> newest so to delete the most recent, you need to parse out the last id in the string and delete it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜