Skip to content

Instantly share code, notes, and snippets.

@wzulfikar
Created February 19, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wzulfikar/23e639efffa63f9f77cbee06e02b3050 to your computer and use it in GitHub Desktop.
Save wzulfikar/23e639efffa63f9f77cbee06e02b3050 to your computer and use it in GitHub Desktop.
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