开发者

How to check if post exists before trying to delete from Facebook

开发者 https://www.devze.com 2023-02-18 16:20 出处:网络
hope you can help me with a bit of a problem I\'ve encountered. I\'m writing a Facebook application where I\'m making posts to user walls to update game score using the PHP SDK.

hope you can help me with a bit of a problem I've encountered.

I'm writing a Facebook application where I'm making posts to user walls to update game score using the PHP SDK.

What I'm trying to do is delete the old post before posting the new one, and that's no problem. Where the problem starts is if the user has manually deleted the old post beforehand. When that's the case, the user's FB session is dropped and all interaction with the API becomes impossible until the user has gone through FB.login again.

The code I'm using is:

try {
    $statusUpdate = $facebook->api('/'.$postID, 'delete');
} catch (FacebookAp开发者_C百科iException $e) {
    d($e);
}

Which works fine if the post exists beforehand.

What I'm wondering is if there's a possibility to do this so that if the delete call fails, it doesn't drop the session and just returns an error that I can handle, or check if the post exists before calling the delete function?

I'd rather not ask users for read_stream permissions on top of publish_stream if I can avoid it.


How about something like:

SELECT post_id FROM stream WHERE post_id='USERID_POSTID'

If the post doesn't exists it would return an empty result.

Please note that USERID_POSTID is your $postID.

0

精彩评论

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