Skip to content

Instantly share code, notes, and snippets.

@rmarscher
Created March 21, 2011 20:10
Show Gist options
  • Save rmarscher/880114 to your computer and use it in GitHub Desktop.
Save rmarscher/880114 to your computer and use it in GitHub Desktop.
PHP function that automates detecting if an open graph page has errors
/**
* Function to automate detecting if an open graph page has errors
* Requires the dom php extension to be enabled
*
* @param string $url
* @return array with keys 'hasError', 'errorType', and 'errorMessage'
*/
function facebookLinterErrors($url)
{
$errorType = "";
$errorMessage = "";
$hasError = false;
try {
$linterPage = DOMDocument::loadHTMLFile("http://developers.facebook.com/tools/lint/?url=" . urlencode($url) . "&_fb_noscript=1");
$error = $linterPage->getElementById('lint_error');
if ($error != null && $error->hasChildNodes()) {
$errorType = $error->lastChild->lastChild->firstChild->nodeValue;
$errorMessage = $error->lastChild->lastChild->lastChild->nodeValue;
$hasError = true;
}
} catch (Exception $e) {}
return compact('hasError', 'errorType', 'errorMessage');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment