我正在尝试从facebook API检索facebook用户名,但我遇到了错误。
我已经尝试了以下代码
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
echo $user=$response->getName();
该代码激励我从facebook中检索用户名并成功运行。当我在浏览器中执行类似的数据显示时
$graphObject = $response->getGraphObject();
echo = $graphObject;
这样显示的数据我知道是GraphObjectFacebook''GraphObject对象
(
[backingData:protected] => Array
(
[id] => 54665634
[first_name] => somePerson
[gender] => male
[last_name] => SomePerson
[link] => https://www.facebook.com/app_scoped_user_id/983427658473566/
[locale] => id_ID
[name] => SomePerson
[timezone] => 7
[updated_time] => 2015-05-13T14:47:40+0000
[verified] => 1
)
)
这是我的问题
致命错误:在第39行调用C:''examplep''htdocs''hacking ''fbtest.php中未定义的方法FacebookResponse::getName()
那么我该怎么解决呢?
您必须在图形对象上使用方法getProperty
$request = new 'Facebook'FacebookRequest($session, 'GET', '/me' );
$response = $request->execute();
$graphObject = $response->getGraphObject();
print_r($graphObject->getProperty('name'));
将在您的案例中打印SomePerson。或者只在图对象上使用asArray
,这将返回私有backingData
变量中的所有信息作为数组。
您可以查看GraphObject.php文件,并了解您可以使用的其他方法:
https://github.com/packetcode/fblogin-basic/blob/master/lib/Facebook/GraphObject.php
新的v2 Graph API不再返回Facebook用户名,因此无法再执行此操作。检查当前文档中可以访问的字段。