Reputation: 125
I have facebook user id, from this id how can I get user's name?
I tried as
$response = file_get_contents('https://graph.facebook.com/' . $userId . '?fields=name');
$user = json_decode($reponse, true);
print_r($user['name']);
exit;
But it has an error file_get_contents(https://graph.facebook.com/"id_of_user"?fields=name): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
Is there any other way to get user name from user id??
[EDIT]
the user's id I am getting are the generated user id's for my app
Upvotes: 0
Views: 2090
Reputation: 74014
You can´t get the username anymore, but i assume you want the real name of the User anyway - which is still possible.
My guess is that your server blocks the request, you should contact your provider. Also, better use CURL instead of file_get_contents.
Btw, you need to use an Access Token for that call if that is an App Scoped ID - which is most likely the case, because there is no way to get the real/global User ID anymore in an App. More information about Access Tokens:
If you don´t know what App Scoped IDs are, take a look at the changelog: https://developers.facebook.com/docs/apps/changelog
Upvotes: 2