2014-12-05 47 views
0

我目前正在一家互聯網公司實習,他們希望我創建一個'品牌檢查器',以便訪問者可以檢查他們的品牌是否在像Facebook這樣的流行網站上,Twitter,LinkedIn等等。graph.facebook.com爲Facebook頁面

我發現通過去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

,你不使用圖表api網址... – Tobi 2014-12-05 15:58:32

回答

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 BTW返回

{ 
    "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 
} 
+0

對不起,遲到的迴應,我還沒有找到時間來回答這個週末。 它運作得非常好,謝謝!我有一個頁面沒有顯示的問題,但這是因爲我必須將'.com'更改爲'.nl'。非常感謝! – Sean 2014-12-08 08:08:47

+0

很好聽。如果有幫助,請接受我的回答。 – Tobi 2014-12-08 08:30:27