Facebook API - getProperty(' source')返回null

时间:2014-11-13 17:04:10

标签: php facebook facebook-graph-api facebook-php-sdk

我正在尝试获取与故事相关联的图像。

图片ID是:562348400566770我已经通过Graph API运行了这个并获得了返回的图像数组

在我的Facebook SDK中,我正在执行以下请求:

$request = new FacebookRequest(
    $session,
    'GET',
    '/'.$image.'/?fields=images'
);
$response = $request->execute();
$images = $response->getGraphObject();

$image_data = $images->getProperty('images');

我也在做一个$ image_data的var_dump,我得到了:

object(Facebook\GraphObject)#5 (1) {
  ["backingData":protected]=>
  array(7) {
    [0]=>
    object(stdClass)#35 (3) {
      ["height"]=>
      int(960)
      ["source"]=>
      string(153) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/10612975_562348400566770_442227994869299119_n.jpg?oh=3415f1e0387bd99b9afdb8a4d043f97e&oe=54E3156D"
      ["width"]=>
      int(720)
    }
    [1]=>
    object(stdClass)#36 (3) {
      ["height"]=>
      int(800)
      ["source"]=>
      string(162) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/p600x600/10612975_562348400566770_442227994869299119_n.jpg?oh=cf421a040e84c64dbdfa325ad96ced91&oe=54D38F13"
      ["width"]=>
      int(600)
    }
    [2]=>
    object(stdClass)#37 (3) {
      ["height"]=>
      int(640)
      ["source"]=>
      string(162) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/p480x480/10612975_562348400566770_442227994869299119_n.jpg?oh=99db9b6a31e4b13074676d95be9bbacb&oe=54D69A0B"
      ["width"]=>
      int(480)
    }
    [3]=>
    object(stdClass)#38 (3) {
      ["height"]=>
      int(426)
      ["source"]=>
      string(166) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/q81/p320x320/10612975_562348400566770_442227994869299119_n.jpg?oh=33959139380a717f4250bc8a186408a4&oe=55175DD7"
      ["width"]=>
      int(320)
    }
    [4]=>
    object(stdClass)#39 (3) {
      ["height"]=>
      int(540)
      ["source"]=>
      string(166) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/q81/p180x540/10612975_562348400566770_442227994869299119_n.jpg?oh=67fec7a39974a4000bbb773925be6370&oe=54D397A1"
      ["width"]=>
      int(405)
    }
    [5]=>
    object(stdClass)#40 (3) {
      ["height"]=>
      int(173)
      ["source"]=>
      string(166) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/q81/p130x130/10612975_562348400566770_442227994869299119_n.jpg?oh=d776025d9a185690d6046c0e345ec6e7&oe=54E3A447"
      ["width"]=>
      int(130)
    }
    [6]=>
    object(stdClass)#41 (3) {
      ["height"]=>
      int(225)
      ["source"]=>
      string(165) "https://scontent-a.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/q81/p75x225/10612975_562348400566770_442227994869299119_n.jpg?oh=c9a4b3e8289a4df07a2fa6a2b6a894b1&oe=54E793B6"
      ["width"]=>
      int(168)
    }
  }
}

我的下一步是获取图像的属性

<img src="<?php echo $images->getProperty('source'); ?>" alt="<?php echo $page_name; ?>" />

然而,当我回显$ images-&gt; getProperty(&#39; source&#39;);返回&#34; NULL&#34;

我错过了一些明显的东西吗?或者是否有更简单的方法来获取图像。

提前致谢。

1 个答案:

答案 0 :(得分:0)

这将为您提供“来源”字段的内容,如果这是您想要的唯一内容:

$images = (new FacebookRequest(
$session, 'GET', '/562348400566770?fields=source'
))->execute()->getGraphObject()->asArray();

echo $images['source'];


对于其他图像大小,您可以调用图像字段,然后访问该数组:

$images = (new FacebookRequest(
$session, 'GET', '//562348400566770?fields=images'
))->execute()->getGraphObject()->asArray();

print_r($images);


来自HTML的直接电话:

<img src="https://graph.facebook.com/562348400566770/picture" />