我目前正在互联网公司实习,他们希望我创建一个“品牌检查器”,以便访问者可以检查他们的品牌名称是否在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也是如此。
提前致谢!
-Sean
答案 0 :(得分:1)
您可以使用端点
https://graph.facebook.com/?id={url}
如https://developers.facebook.com/docs/graph-api/reference/v2.2/url/所示,检查该网址是否有object_id
。 URL也可以是Facebook页面链接,例如
https://graph.facebook.com/?id=https://www.facebook.com/fgshdioghsdlfghsldfgkl
非拍摄网址( - &gt; 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
}