这是图api代码,我通过它获取全名,电子邮件和Facebook ID ..我需要的是只通过图形api得到用户的名字,但我不知道如何做到这一点?任何帮助。
$request = new FacebookRequest($sess, 'GET', '/me');
// from response get graph object
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::className());
// use graph object methods to get user details
$graphObject = $response->getGraphObject();
$fuid = $graphObject->getProperty('id'); // To Get Facebook ID
$ffname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); //email
答案 0 :(得分:3)
喜欢这个吗?
$firstName = $graphObject->getProperty('first_name');
如果您仍然没有得到它,请尝试使用其他API调用:
/me?fields=first_name
答案 1 :(得分:0)
您可以修改您的代码,包括您需要的所有字段,包括first_name,例如以下代码,包括ID,全名,名字,姓氏和电子邮件
$request = new FacebookRequest( $session, 'GET', '/me?fields=id,name,first_name,last_name,email' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbfirstname = $graphObject->getProperty('first_name'); // get Facebook first name