2011-08-31 44 views
1

我有一個名稱列表,我需要匹配Facebook個人資料圖片,沒有access_token。 使用 http://graph.facebook.com/USERNAME/picture來獲取圖片只有在用戶擁有用戶名時才起作用。在php中爲用戶獲取自動配置文件圖片?

最好的辦法是做什麼?

另外我看了一下pipl.com,他們很容易就用名字取得myspace和facebook個人資料圖片。

回答

0

好吧,這是我想出的代碼: 你輸入someones全名,它會得到一個配置文件圖像,因爲你有一個訪問令牌。

<?php $fullname= get_the_title(); //gets users name 
$data = file_get_contents('https://graph.facebook.com/search?q='.urlencode($fullname).'&type=user&access_token=...'); //Querys FB ID from facebook graph api 
$lessdata = substr($data, strpos($data,'id":"') + 5); //Removes evrything before the start of the FB ID 
$fbid = substr($lessdata, 0, strpos($lessdata, '"')); // removes everything after the FB ID 
$fbimage = 'https://graph.facebook.com/'.$fbid.'/picture'; echo '<img src="'.$fbimage.'"/>' ?> 
1

如果您只有名字,您可以使用圖形API進行搜索,但除非名稱是唯一的,否則可能會返回大量結果。

https://graph.facebook.com/search?q=mark%20zuckerberg&type=user&access_token= ...

您可以使用任何訪問令牌該搜索,如一個Graph API explorer給你。

+0

這很有幫助,但是如何獲取頂級搜索結果的個人資料圖片? – Steven

+0

http://graph.facebook.com/4/picture或任何身份證。 – bkaid

+0

但是我可以直接在php代碼中做到這一點。而無需手動傳送用戶標識。感謝您的迴應btw。 – Steven

相關問題