Facebook API PHP-Posts';创建时间';数据显示不正确

Facebook API PHP-Posts';创建时间';数据显示不正确,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,我正在使用PHP制作一个Facebook应用程序。通过Facebook API,应用程序显示登录用户最近发布的帖子。在检索每篇文章的创建时间时,我发现它要么没有显示任何内容,要么只显示1970-01-01T00:00:00+0000。(这可以在下图中看到。)即使我使用了DateTime,这一点仍然有效 它应该返回类似于2016-01-31T16:31:26+0000,如使用Facebook的Graph API Explorer所示 不确定如何更正此问题,我能够使其以正确的格式显示,如下所示: $

我正在使用PHP制作一个Facebook应用程序。通过Facebook API,应用程序显示登录用户最近发布的帖子。在检索每篇文章的
创建时间时,我发现它要么没有显示任何内容,要么只显示
1970-01-01T00:00:00+0000
。(这可以在下图中看到。)即使我使用了
DateTime
,这一点仍然有效

它应该返回类似于
2016-01-31T16:31:26+0000
,如使用Facebook的Graph API Explorer所示

不确定如何更正此问题,我能够使其以正确的格式显示,如下所示:

$ts = strtotime($key['created_time']);
$myTime = gmdate(DATE_ISO8601, $ts);
所有的信息都是从Facebook获取的,并且都在一个
foreach
循环中。它浏览每一篇文章,知道把什么放在哪里,每一个
created\u time
值都被设置为
$key['created\u time']

前端示例

图形API浏览器

这是我的代码:

<?php

    // Getting all posts published by user
    try {
        $posts_request = $fb->get('/me/posts?fields=id,created_time,message,link,picture,name&limit=7');
        $posts_response = $posts_request->getGraphEdge();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }


    if ($fb->next($posts_response))  {
        $total_posts = $posts_response->asArray();
        $totalPosts = count($total_posts);

        // Form - Post
            echo "<p><strong>* With this text box below, you can post to your Facebook Profile about your experience using this application if you wish. Once submitted, this post will then also appear in the list of your other posts below.</strong></p>";
            echo "<form action='posttouserstimeline.php' method='post'>";
            echo "<textarea name='description' class='posts'></textarea>";
            echo "<br><br>";
            echo "<input type='submit' class='webbutton' value='Post to Facebook'>";
            echo "</form>";
            echo "<br>";
            echo "<p><strong>* Below are your '5' most resent posts, from your Facebook Profile</strong></p>";

            //$date = new DateTime($key['created_time']);

        foreach($total_posts as $key) {

            $ts = strtotime($key['created_time']);
            $myTime = gmdate(DATE_ISO8601, $ts);

            echo "Time and Date of Post: ".$myTime."<br>";
            echo "<img class='postsprofile' alt='profilepic' src='".$picture['url']."'/> <a href='https://facebook.com/".$profile['id']."' target='_blank'>".$profile['name']."</a><br>";
            echo $key['message'].'<br><br>';
             echo "<a href='".$key['link']."' target='_blank'><img class='postsprofile' alt='".$key['name']."' src='".$key['picture']."'/></a><br><hr><br>";

            //echo "<img class='postsprofile' alt='".$key['name']."' src='".$key['picture']."'/><br>";
            //echo "<a href='".$key['link']."' target='_blank'>".$key['link']."</a><br><hr><br>";
        }
    }

问题在于facebook的时间函数没有以标准数字形式给出从strotime呼叫到工作所需的时间。这是我在网上找到的一个函数,它将facebook时间转换为我们习惯的标准数字形式的时间

var fuzzyFacebookTime = (function(){

  fuzzyTime.defaultOptions={
    // time display options
    relativeTime : 48,
    // language options
    monthNames : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    amPm : ['AM', 'PM'],
    ordinalSuffix : function(n) {return ['th','st','nd','rd'][n<4 || (n>20 && n % 10<4) ? n % 10 : 0]}
  }

  function fuzzyTime (timeValue, options) {

    var options=options||fuzzyTime.defaultOptions, 
        date=parseDate(timeValue),
        delta=parseInt(((new Date()).getTime()-date.getTime())/1000),
        relative=options.relativeTime,
        cutoff=+relative===relative ? relative*60*60 : Infinity;

    if (relative===false || delta>cutoff)
      return formatTime(date, options)+' '+formatDate(date, options);

    if (delta<60) return 'less than a minute ago';
    var minutes=parseInt(delta/60 +0.5);
    if (minutes <= 1) return 'about a minute ago';
    var hours=parseInt(minutes/60 +0.5);
    if (hours<1) return minutes+' minutes ago';
    if (hours==1) return 'about an hour ago';
    var days=parseInt(hours/24 +0.5);
    if (days<1) return hours+' hours ago';
    if (days==1) return formatTime(date, options)+' yesterday';
    var weeks=parseInt(days/7 +0.5);
    if (weeks<2) return formatTime(date, options)+' '+days+' days ago';
    var months=parseInt(weeks/4.34812141 +0.5);
    if (months<2) return weeks+' weeks ago';
    var years=parseInt(months/12 +0.5);
    if (years<2) return months+' months ago';
    return years+' years ago';
  }

  function parseDate (str) {
    var v=str.replace(/[T\+]/g,' ').split(' ');
    return new Date(Date.parse(v[0] + " " + v[1] + " UTC"));
  }

  function formatTime (date, options) {
    var h=date.getHours(), m=''+date.getMinutes(), am=options.amPm;
    return (h>12 ? h-12 : h)+':'+(m.length==1 ? '0' : '' )+m+' '+(h<12 ? am[0] : am[1]);
  }

  function formatDate (date, options) {
    var mon=options.monthNames[date.getMonth()],
        day=date.getDate(),
        year=date.getFullYear(),
        thisyear=(new Date()).getFullYear(),
        suf=options.ordinalSuffix(day);

    return mon+' '+day+suf+(thisyear!=year ? ', '+year : '');
  }

  return fuzzyTime;

}());
var fuzzyFacebookTime=(函数(){
fuzzyTime.defaultOptions={
//时间显示选项
相对时间:48,
//语言选项
月份名称:[一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月],
amPm:['AM','PM'],
ordinalSuffix:函数(n){return['th','st','nd','rd'][n20&&n%10cutoff)
返回格式时间(日期,选项)+''+格式日期(日期,选项);
if(delta