No result displayed in retrieving User data in facebook iFrame application using users_getInfo()
I'm writing a Facebook iframe/Facebook Connect application with PHP client library and in one of the pages, I need to retrieve the user's current location, either city or country.
I have added "Request for Permission" for all possible data in my index file.
$user_id = $开发者_JAVA技巧facebook->require_login($required_permissions = 'user_location,publish_stream,email,read_stream,user_about_me,user_activities,user_birthday,user_hometown,user_interests,user_likes,user_status);
This is the code I am using in my application,
$userInfo = $facebook->api_client->users_getInfo($user_id, array('current_location'));
var_dump($userInfo);
$location = ($userInfo[0]) ? $userInfo[0]['current_location'] : $userInfo['current_location'];
echo "UserInfo : ".$location;
The result of var_dump($userInfo) is string(0)""
and echo of $location is empty.
Please someone help me.
That's because you made an error when copying the example. You have the method signature wrong.
// Your version
$facebook->api_client->users_getInfo($user_id,'last_name','first_name');
// From the example
$facebook->api_client->users_getInfo($uid, 'last_name, first_name');
See the difference? It's only two parameters - the 2nd is a comma-separated list of field names.
So, since you are not correctly requesting the first_name
field from the API, it's not available in the response.
Hence the error when trying to read it.
精彩评论