Steven
Steven

Reputation: 13

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. Using 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.

Upvotes: 1

Views: 957

Answers (3)

Carfire
Carfire

Reputation: 49

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

Upvotes: 1

Steven Baltay
Steven Baltay

Reputation: 554

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

Upvotes: 0

bkaid
bkaid

Reputation: 52083

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.

Upvotes: 1

Related Questions