我使用的是最新版本的Facebook PHP SDK(版本4)。我终于明白了如何在我的PHP代码中使用它。下面是我的代码。
$user_profile = (new FacebookRequest($this->session, 'GET', '/me/?fields=id,first_name,last_name,picture,timezone,gender,link'))->execute()->getGraphObject(GraphUser::className());
$outputArray[$i]['first_name'] = $user_profile->getFirstName();
$outputArray[$i]['last_name'] = $user_profile->getLastName();
$outputArray[$i]['pictureURL'] = ;
我指定什么来接收我请求的图片URL?
此外,我手动打开了名为GraphUser.php的fb-php-sdk文件,只是想看看我自己是否能找到该属性。它在pastebin上。
http://pastebin.com/K6Xg0MjN
正如你所看到的,GraphUser对象不包含任何处理图片的属性,那么我从哪里得到图片呢?
请阅读
不是用户对象的名为picture
的字段。这是一个优势:
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/picture
$picture_info = (new FacebookRequest($this->session, 'GET', '/me/picture'))->execute()->getGraphObject();
$outputArray[$i]['pictureURL']=$picture_info->getProperty('url');