开发者

Getting automatic profile pics for users in php?

I have a list of names that I need to match with facebook profile pictures, without an access_token. U开发者_运维知识库sing http://graph.facebook.com/USERNAME/picture to get the pictures only seems to work if the user has a username.

Whats the best way to do this?

Also I took a look at pipl.com and they manage to fetch myspace and facebook profile images very easily with just a name.


If you only have names, you could use the graph API to search but unless the name is unique you will get back a lot of results potentially.

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

You can use any access token for that search, such as the one the Graph API explorer gives you.


You can use get this in either way http://graph.facebook.com/USERNAME/picture or http://graph.facebook.com/USERID/picture.


Ok this is the code I came up with: You enter someones full name and it gets a profile image, given you have an access token.

<?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.'"/>' ?> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜