使用 users_getInfo() 在 facebook iFrame 应用程序中检索用户数据时未显示结果

发布于 2024-09-10 18:19:55 字数 755 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话里做英雄 2024-09-17 18:19:55

那是因为您在复制示例时犯了错误。您的方法签名错误。

// 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'); 

看到区别了吗?它只有两个参数 - 第二个参数是逗号分隔的字段名称列表。

因此,由于您没有从 API 正确请求 first_name 字段,因此它在响应中不可用。

因此在尝试读取它时会出现错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文