如何使用php获取facebook相册照片id和时间?

如何使用php获取facebook相册照片id和时间?,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我是php新手。我用下面两个代码来获取facebook相册照片id和创建时间。但它不起作用,不向我显示结果/ID,只向我显示空白页 下面是我的两段代码,其中包含$json和$array输出 代码1 <?php $token="<token>"; $data = file_get_contents("https://graph.facebook.com/106097030098624/photos?fields=id&access_token=$token"); $j

我是php新手。我用下面两个代码来获取
facebook
相册照片id和创建时间。但它不起作用,不向我显示结果/ID,只向我显示空白页

下面是我的两段代码,其中包含$json和$array输出

代码1

<?php 
$token="<token>"; 
$data = file_get_contents("https://graph.facebook.com/106097030098624/photos?fields=id&access_token=$token");
$json = json_decode($data); 
echo $json->id;
echo $json->created_time;
?>
代码2:

<?php
$token="<token>";
$data = file_get_contents("https://graph.facebook.com/106097030098624/photos?fields=id&access_token=$token");
$array = json_decode($data, true);
echo $array['data']['id'];
echo $array['data']['created_time'];
?>
请帮助我解决此问题。感谢您第一次需要执行的操作:-


对于第二个,您可以使用:-



输出:-

do
var\u dump($json)
var\u dump($array)在代码1,2中,就在
json\u decode()
行之后,看看输出是什么?显示usi编辑和添加的输出。@MasudRana也请投票表决答案。很高兴帮助您:):)
<?php
$token="<token>";
$data = file_get_contents("https://graph.facebook.com/106097030098624/photos?fields=id&access_token=$token");
$array = json_decode($data, true);
echo $array['data']['id'];
echo $array['data']['created_time'];
?>
array(2) {
  ["data"]=>
  array(3) {
    [0]=>
    array(2) {
      ["id"]=>
      string(15) "160246594547781"
      ["created_time"]=>
      string(24) "2017-08-04T18:09:13+0000"
    }
    [1]=>
    array(2) {
      ["id"]=>
      string(15) "160246581214449"
      ["created_time"]=>
      string(24) "2017-08-04T18:09:12+0000"
    }
    [2]=>
    array(2) {
      ["id"]=>
      string(15) "160246587881115"
      ["created_time"]=>
      string(24) "2017-08-04T18:09:13+0000"
    }
  }
  ["paging"]=>
  array(1) {
    ["cursors"]=>
    array(2) {
      ["before"]=>
      string(20) "MTYwMjQ2NTk0NTQ3Nzgx"
      ["after"]=>
      string(20) "MTYwMjQ2NTg3ODgxMTE1"
    }
  }
}
<?php 
$token="<token>"; 
$data = file_get_contents("https://graph.facebook.com/106097030098624/photos?fields=id&access_token=$token");
$json = json_decode($data); 
foreach($array.data as $arr){
  echo $arr.id; echo PHP_EOL; // you can use `echo "<br/>";`
  echo $arr.created_time;echo PHP_EOL;// you can use `echo "<br/>";`
 }
?>
<?php
$token="<token>";
$data = file_get_contents("https://graph.facebook.com/106097030098624/photos?
fields=id&access_token=$token");
$array = json_decode($data, true);
foreach($array['data'] as $arr){
  echo $arr['id']; echo PHP_EOL; // you can use `echo "<br/>";`
  echo $arr['created_time'];echo PHP_EOL;// you can use `echo "<br/>";`
 }
?>