I am creating website to search places using graph API. I got the places details from graph API. Is there any way to get the page rating and reviews of the places via graph API?
David R. Myers II's answer is just what I needed. Thank you!
You can get the overall_star_rating
and the rating_count
fields of any page.
You need to submit your app for review by Facebook and request to use the Page Public Content Access feature.
For developing, while your Facebook app status is In development
you automatically have access to the public content for pages that you own. Before going live, request a review from Facebook so you can access other pages.
To list pages you own: https://www.facebook.com/bookmarks/pages?ref=u2u
Sample code to get the ratings:
// Assuming the Facebook PHP SDK was installed with Composer.
require_once __DIR__ . '/vendor/autoload.php'; // Change path as needed.
$fb = new \Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v3.2',
'default_access_token' => '{access-token}',
]);
try {
// Get the \Facebook\GraphNodes\GraphPage object for the needed page.
$response = $fb->get('/{page-id}?fields=overall_star_rating,rating_count');
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// Get the response typed as a GraphPage.
$page = $response->getGraphPage();
// Get the needed field values.
$facebook_rating_count = $page->getField( 'rating_count' );
$facebook_overall_star_rating = $page->getField( 'overall_star_rating' );