graph.facebook.com 用于 Facebook 页面

问题描述 投票:0回答:1

我目前在一家互联网公司实习,他们希望我创建一个“品牌检查器”,以便访问者可以检查他们的品牌名称是否被 Facebook、Twitter、LinkedIn 等热门网站占用。

我发现通过访问 http://graph.facebook.com/,您可以查看 Facebook 上是否存在某个人/帐户。我目前正在尝试找到一种方法来检查 Facebook 上是否存在页面。我不需要帖子之类的细节,我只需要找出它是否存在。

到目前为止,我已经尝试了下面的代码(注释的代码和未注释的代码),但它根本不起作用。

<?php
/*$z = file_get_contents("http://www.facebook.com/search/results/?q=example");
preg_match("#LifeStamp#s", $z, $matches);
echo $matches[1];
if($matches == 1){
    echo "In there!";
    } elseif($matches == 0) {
    echo "No";
    } elseif($matches == "false") {
    echo "Nope";
    } else {
    echo "Nopenopenope";
    };*/
$ch = curl_init(); 
$timeout = 0; 
curl_setopt ($ch, CURLOPT_URL, 'http://www.facebook.com/search/results/?q=example'); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$file_contents = curl_exec($ch); 
curl_close($ch); 

var_dump($file_contents);
echo $file_contents[1];
?>

file_get_contents()
给出错误(顺便说一下
url_get_contents()
也是如此)。
curl
部分仅返回一个空白页。

TL;DR: 有没有一种(最好是简单的)方法可以让我检查 Facebook 页面是否存在?如果你们碰巧知道的话,Twitter 和 LinkedIn 也是如此。

提前致谢!

-肖恩

php facebook facebook-graph-api
1个回答
1
投票

您可以使用端点

https://graph.facebook.com/?id={url}

https://developers.facebook.com/docs/graph-api/reference/v2.2/url/所示检查该URL是否有

object_id
。例如,URL 也可以是 Facebook 页面链接

https://graph.facebook.com/?id=https://www.facebook.com/fgshdioghsdlfghsldfgkl

未采用的 URL(-> Facebook 页面)的响应是

{
   "id": "https://www.facebook.com/fgshdioghsdlfghsldfgkl"
}

与所拍摄的 Facebook 页面相反:

https://graph.facebook.com/?id=https://www.facebook.com/cocacola

whcih 返回

{
   "id": "40796308305",
   "about": "The Coca-Cola Facebook Page is a collection of your stories showing how people from around the world have helped make Coke into what it is today.",
   "can_post": false,
   "category": "Food/beverages",
   "checkins": 13624,
   "cover": {
      "cover_id": "10152297032458306",
      "offset_x": 0,
      "offset_y": 0,
      "source": "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-prn2/v/t1.0-9/s720x720/625442_10152297032458306_574021701_n.jpg?oh=4bcbc7e195383a2c41c99f2d9a76a41b&oe=54FFAEE9&__gda__=1426811392_edb8ee0782ce0143ba26abb724e7bc82",
      "id": "10152297032458306"
   },
   "description": "Created in 1886 in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage at Jacob's Pharmacy by mixing Coca-Cola syrup with carbonated water. \n\nCoca-Cola was patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States. \n\nCoca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world.\n\nCoca-Cola Page House Rules: http://CokeURL.com/q28a",
   "founded": "1886",
   "has_added_app": false,
   "is_community_page": false,
   "is_published": true,
   "likes": 91176186,
   "link": "https://www.facebook.com/coca-cola",
   "name": "Coca-Cola",
   "parking": {
      "lot": 0,
      "street": 0,
      "valet": 0
   },
   "talking_about_count": 1306671,
   "username": "coca-cola",
   "website": "http://www.coca-cola.com",
   "were_here_count": 0
}
© www.soinside.com 2019 - 2024. All rights reserved.