Created
February 19, 2017 12:18
-
-
Save wzulfikar/23e639efffa63f9f77cbee06e02b3050 to your computer and use it in GitHub Desktop.
Get FB User Profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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