Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get FB User Profile
<?php
/**
* fetch profile of given fb's user id. fields are optional.
*/
function getFbProfile($userId, array $fields = [])
{
$ACCESSS_TOKEN = 'YOUR_TOKEN_HERE';
$BASE_URL = 'https://graph.facebook.com/v2.6';
// fetch default fields if no fields passed
if (empty($fields)) {
$fields = [
'first_name',
'last_name',
'profile_pic',
'locale',
'timezone',
'gender'
];
}
$endpoint = sprintf("%s/%s?fields=%s&access_token=%s",
$BASE_URL,
$userId,
implode(',', $fields),
$ACCESSS_TOKEN
);
return json_decode(file_get_contents($endpoint), true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment