Reputation: 2038
I am getting a fatal php error: "Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /facebook-php-sdk/src/base_facebook.php on line 1340"
, when making an api call on posts that have been deleted on facebook. i want to be able to delete the post from my database if the post has been deleted from facebook and also remove this fatal error. my api call is in a while loop to return the top posts (ranked on comments, shares and likes). i need to check for the existence of the post before returning the post and delete it from database if removed from facebook.
$get_content_db_info = mysqli_query($dbc , "SELECT * FROM `content`");
echo '<table id="leaugeTable"><thead><tr><th>Name</th><th>Post ID</th><th>Facebook ID</th><th>Score</th></tr></thead><tbody>';
while($row = mysqli_fetch_array($get_content_db_info)){
// then your for loop
$fbApiGetPosts = $facebook->api('/'.$row["fb_id"].'_'.$row["post_id"]);
$fbApiGetShares = $fbApiGetPosts["shares"];
$shareCount = $fbApiGetShares["count"];
$fbApiGetLikes = $facebook->api('/'.$row["post_id"].'/likes');
$countLikes = $fbApiGetLikes["data"];
$likesResult = count($countLikes);
$fbApiGetComments = $facebook->api('/'.$row["post_id"].'/comments');
$countComments = $fbApiGetComments["data"];
$cc = count($countComments);
$score = $likesResult + $shareCount * 2 + $cc * 3;
echo '<tr><td>'.$row["first_name"].' '.$row["last_name"].'</td><td>'.$row["post_id"].'</td><td>'.$row["fb_id"].'</td><td class = "sortCol">'.$score.'</td></tr>';
}
this is my first facebook project and dont know how to go about this.
Upvotes: 0
Views: 613
Reputation: 15457
If the post has been deleted from facebook, you'll see the Fatal error: Uncaught GraphMethodException: Unsupported get request.
error. What you can do is:
while($row = mysqli_fetch_array($get_content_db_info)){
try {
// your original while code
} catch ( Exception $e ) {
// error from facebook, post is likely to be deleted
if ( $ex->getMessage() === 'Unsupported get request.' ) {
// delete post from database
}
}
}
The try...catch statement will catch any errors, including Unsupported get request.
, where you can then delete the post from the database, without affecting the rest of the flow.
Upvotes: 2