Skip to content

Commit

Permalink
Add some sanity checking
Browse files Browse the repository at this point in the history
We're checking if $graphdata was a valid JSON string ($response will be false if it wasn't), we check if $response is an array and if the "likes" key is actually set.
  • Loading branch information
Mark-H committed Apr 15, 2012
1 parent e53b150 commit c2306e9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fblikes.snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
$graphdata = file_get_contents("http://graph.facebook.com/".$pageid);
// decode json response
$response = $modx->fromJSON($graphdata);
if (!$response || !is_array($response) || !isset($response['likes'])) {
return 'Data currently not available.';
}
// get like number
$data = $response['likes'];

Expand Down

0 comments on commit c2306e9

Please sign in to comment.