简体   繁体   English

检索Facebook个人资料图片的URL

[英]Retrieving URL of Facebook profile picture

I have the following code that has a correct output: 我有以下代码具有正确的输出:

$request = new FacebookRequest( $session, 'GET', '/me?fields=id,first_name,email,gender,birthday,picture.url' );
$response = $request->execute();

OUTPUT: OUTPUT:

Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => 1412361249046879 [first_name] => Do [email] => xxxx@xxxx.com [gender] => male [birthday] => 06/30/1984 [picture] => stdClass Object ( [data] => stdClass Object ( [url] => https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpa1/t1.0-1/p50x50/10406555_1412406989042185_8978818317524743009_t.jpg ) ) ) )

Then I set variables to call later in my html: 然后设置变量以供以后在html中调用:

  $uid = $response->getGraphObject()->getProperty('id');
  $name = $response->getGraphObject()->getProperty('first_name');
  $email = $response->getGraphObject()->getProperty('email');
  **$pic = $response->getGraphObject()->getProperty('picture.data.url');**
  $sex = $response->getGraphObject()->getProperty('gender');
  $bday = $response->getGraphObject()->getProperty('birthday');

The problem is the $pic variable doesn't work. 问题是$ pic变量不起作用。 I don't understand how to call the variable that is further down the GraphObject tree (ie. picture->data->url) 我不明白如何调用位于GraphObject树下方的变量(即picture-> data-> url)

$request = new FacebookRequest( $session, 'GET', '/me?fields=id,first_name,email,gender,birthday,picture.url' );
$response = $request->execute();      
$array = $response->getResponse();
$pic = $array->picture->data->url;

Here is what ended up solving it. 这就是解决问题的方法。 I had to stop using the getGraphObject() function and just use the standard getResponse() so that I could treat it more like a regular array. 我不得不停止使用getGraphObject()函数,而只是使用标准的getResponse(),以便可以将其更像是常规数组。 Hope this helps somebody out. 希望这可以帮助到别人。

Why you dont call it like this: 为什么不这样称呼它:

$pic = $response->getGraphObject()->getProperty('picture')->data->url;

OR use FQL with FB SDK 或将FQL与FB SDK一起使用

$config = array(
  'appId'  => APP_ID,
  'secret' => API_SECRET,
  'cookie' => true,

);
$facebook = new Facebook($config);
$params = array(
    'method' => 'fql.query',
    'query' => "SELECT uid,email, pic, first_name, last_name, birthday, sex FROM user WHERE uid = ".$uid.""
    );

$result = $result = $facebook->api($params);

Here is the full table of user and official PHP SDK . 这是用户和官方PHP SDK的完整 I hope this helps. 我希望这有帮助。

Warning: But FQL it will be removed from new version of FB API. 警告:但是FQL将从新版本的FB API中删除。

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

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