简体   繁体   English

获取用户个人资料上的特定字段。 Facebook SDK PHP

[英]Get specific fields on user profile. Facebook SDK PHP

I've created a FB app for a client succesfully. 我已经成功为客户端创建了FB应用。 However, when I fist time load the app, it takes too much time retrieving users' profile in API 但是,当我第一时间加载应用程序时,在API中检索用户个人资料会花费太多时间

$user_profile = $facebook->api('/me');

In order to reduce the loading time in my page, I just wanna to get the specific fields I need. 为了减少页面的加载时间,我只想获取所需的特定字段。 Is it possible, for example, get only 'username' or 'name' fields? 例如,是否有可能仅获得“用户名”或“名称”字段?

Thank you 谢谢

Sure you can. 你当然可以。

$user_profile = $facebook->api('/me?fields=name,username');

But I'm not sure it is going to be faster. 但是我不确定它会更快。

More fields can be found in the doc . 可以在文档中找到更多字段。

Well, you need to read some documentation , there is a lot regarding PHP and Facebook . 好吧,您需要阅读一些documentation ,有关PHPFacebook的内容很多。

To get the name you can do the following: 要获取name您可以执行以下操作:

$name = $user_profile['name'];

To get the username will be easy too ( I don't remember exactly what's the key for the username in that array ), but you can print all the information from $user_profile by doing the following: 获取username也很容易( 我不记得确切的username是该array usernamekey ),但是您可以通过执行以下操作来print $user_profile的所有信息:

print_r($user_profile);

or 要么

var_dump($user_profile);

Then you can capture what you need doing the same way as above. 然后,您可以按照上述相同的方式捕获所需的内容。

You can retrieve user id in facebook by: 您可以通过以下方式在Facebook中检索用户ID:

echo $user_profile['id'];

You can retrieve name by: 您可以通过以下方式检索名称:

echo $user_profile['name'];

Retrieve user first name , last name or middle name: 检索用户的名字,姓氏或中间名:

echo $user_profile['first_name'];

echo $user_profile['last_name'];

echo $user_profile['middle_name'];

Retrieve user location name: 检索用户位置名称:

echo $user_profile['location']['name'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM