在Facebook Graph API中,要获取用户的电子邮件地址和性别的API调用是什么? [英] In Facebook Graph API, what are the API calls to get a user's email address and gender?

查看:117
本文介绍了在Facebook Graph API中,要获取用户的电子邮件地址和性别的API调用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助此链接,我正在使用Graph API和Facebook SDK for PHP: https://developers.facebook.com/docs/php/howto/profilewithgraphapi/4.0.0 .这是代码:

I'm using the Graph API and the Facebook SDK for PHP with the help of this link: https://developers.facebook.com/docs/php/howto/profilewithgraphapi/4.0.0. This is the code:

use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

if($session) {

  try {

    $user_profile = (new FacebookRequest(
      $session, 'GET', '/me'
    ))->execute()->getGraphObject(GraphUser::className());

    echo "Name: " . $user_profile->getName();

  } catch(FacebookRequestException $e) {

    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();

  }   

}

根据我的API调用,我可以使用user_profile->getName();来获取用户名,也可以获取他/她的名字,姓氏,中间名等. : https://developers.facebook.com/docs/php/GraphObject /#user-instance-methods .我知道可以获取用户的电子邮件地址和性别,但是在上一个链接中,我没有找到任何API调用来获取此信息.

I'm at the point where I'm able to get a user's name by using user_profile->getName();, I can also get his/her first name, last name, middle name, etc., according to the API calls here: https://developers.facebook.com/docs/php/GraphObject/#user-instance-methods. I know it is possible to get a user's email address and gender, but in the previous link I didn't find any API calls to be able to get this information.

对于用于PHP的Facebook SDK,要获取用户的电子邮件地址和性别的API调用是什么?

For Facebook SDK for PHP, what are the API calls to get a user's email address and gender?

非常感谢您.

推荐答案

看看

  • https://developers.facebook.com/docs/graph-api/reference/v2.2/user#fields
  • https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#fields

概述,您可以查询用户对象的哪些字段和边.就您而言,应该是

to get an overview what fields and edges you can query for the user object. In your case, that should be

/me?fields=id,gender,email

new FacebookRequest(
  $session, 'GET', '/me?fields=id,gender,email'
)

请注意,您需要具有user_email权限才能请求email字段.

Be aware that you'll need the user_email permission to be able to request the email field.

要获取特定字段,请使用getProperty()方法,如 https://developers.facebook.com/docs/php/GraphObject/#getproperty

To get specific fields, use the getProperty() method as described at https://developers.facebook.com/docs/php/GraphObject/#getproperty

echo $user_profile->getProperty('gender');

这篇关于在Facebook Graph API中,要获取用户的电子邮件地址和性别的API调用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆