使用 users_getInfo() 在 facebook iFrame 应用程序中检索用户数据时未显示结果
我正在使用 PHP 客户端库编写 Facebook iframe/Facebook Connect 应用程序,在其中一个页面中,我需要检索用户的当前位置(城市或国家/地区)。
我已在索引文件中为所有可能的数据添加了“请求许可”。
$user_id = $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);
这是我在应用程序中使用的代码,
$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;
var_dump($userInfo) 的结果是 string(0)""
并且 $location 的 echo 为空。
请有人帮助我。
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 = $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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为您在复制示例时犯了错误。您的方法签名错误。
看到区别了吗?它只有两个参数 - 第二个参数是逗号分隔的字段名称列表。
因此,由于您没有从 API 正确请求
first_name
字段,因此它在响应中不可用。因此在尝试读取它时会出现错误。
That's because you made an error when copying the example. You have the method signature wrong.
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.