简体   繁体   English

使用Graph api获取facebook页面评价和评论

[英]Get facebook page rate and reviews using Graph api

I am creating website to search places using graph API. 我正在创建使用图API API搜索地点的网站。 I got the places details from graph API. 我从图API中获取了地方详细信息。 Is there any way to get the page rating and reviews of the places via graph API? 有没有办法通过图形API获取页面评级和地点评论?

I had the same problem and I answered my own question here : 我有同样的问题,我在这里回答了我自己的问题:

you need to call {page-id}/ratings?field=open_graph_story , but you need the access token of your page for that (use /me/accounts in the Graph API Explorer to get the token). 你需要调用{page-id} / ratings?field = open_graph_story ,但你需要你的页面的访问令牌(在Graph API Explorer中使用/ me / accounts来获取令牌)。 You find further information in the facebook documentation . 您可以在facebook文档中找到更多信息。

This is an old post, but I wanted to give some extra info to others that might be looking for a solution to this problem still. 这是一篇旧帖子,但我想给其他可能正在寻找解决这个问题的解决方案。 As stated in the Facebook Open Graph documentation , you definitely need a page access token to get the page's individual ratings/reviews . Facebook Open Graph文档中所述您肯定需要一个页面访问令牌来获取页面的个人评级/评论 If you are looking for the overall rating and the count of reviews , however, you are in luck. 但是,如果您正在寻找整体评分评论数量 ,那么您很幸运。 By simply making a call to /{page-id}?fields=overall_star_rating,rating_count , you will be able to access that data. 只需拨打/{page-id}?fields=overall_star_rating,rating_count ,您就可以访问该数据。

Here's an example response: 这是一个示例响应:

{
    "overall_star_rating": 4.7,
    "rating_count": 31,
    "id": "{page-id}"
}

David R. Myers II's answer is just what I needed. David R. Myers II的回答正是我所需要的。 Thank you! 谢谢! You can get the overall_star_rating and the rating_count fields of any page. 您可以获取任何页面的overall_star_ratingrating_count字段。

You need to submit your app for review by Facebook and request to use the Page Public Content Access feature. 您需要提交您的应用以供Facebook审核并请求使用页面公共内容访问功能。

For developing, while your Facebook app status is In development you automatically have access to the public content for pages that you own. 对于开发,当您的Facebook应用程序状态为In development您可以自动访问您拥有的页面的公共内容。 Before going live, request a review from Facebook so you can access other pages. 在上线之前,请从Facebook请求审核,以便您可以访问其他页面。

To list pages you own: https://www.facebook.com/bookmarks/pages?ref=u2u 列出您拥有的页面: 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' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM