无法使用simplepie将谷歌事件链接到谷歌日历



我使用php-include(强制)和simplepie来获取事件标题和开始日期,但它一直为每个事件提供2013年8月8日。我能很好地看到这些事件。知道如何从中获取"when"标签吗?如果我使用标签,我会出错。我不是php的专业人士,现在我已经无计可施了!

       <?php
  if ($_SERVER['QUERY_STRING']) {
     parse_str($_SERVER['QUERY_STRING'], $arg);
  } else {
     $arg['feed'] = '';
     $arg['count'] = '';
     $arg['more'] = '';
     $arg['nodiv'] = '';
  }
  if (!isset($arg['nodiv'])) $arg['nodiv']='false';
  if ($arg['nodiv'] != 'true') {
?>


 <div id="news_list">
<?php
  }
  include('simplepie.inc');
// Let's create a new SimplePie object
$feed = new SimplePie();
$feed = new SimplePie();
  $feed->set_file($file);
  $feed->enable_cache(false);   
  $feed->init();
  $feed->handle_content_type();
// This is the feed we'll use
$feed->set_feed_url('http://www.google.com/calendar/feeds/aufdccetl%40gmail.com/public/full?max-results=2');

// Let's turn this off because we're just going to re-sort anyways, and there's no reason to waste CPU doing it twice.
$feed->enable_order_by_date(false);
// Initialize the feed so that we can use it.
$feed->init();
// Make sure the content is being served out to the browser properly.
$feed->handle_content_type();
// We'll use this for re-sorting the items based on the new date.
$temp = array();

foreach ($feed->get_items() as $item) {

    // We want to grab the Google-namespaced <gd:when> tag.
    $when = $item->get_item_tags('http://schemas.google.com/g/2005', 'when');

    // Once we grab the tag, let's grab the startTime attribute
    $date = $when[0]['attribs']['']['startTime'];
    // Let's convert it all to UNIX timestamp. This will be used for sorting.
    $sortDate = SimplePie_Misc::parse_date($date);
    // Let's format it with date(). This will be the date we display.
    $gCalDate = date('l, F j, Y', $sortDate);
    // This is how each item will be displayed. We're adding it to the array we created earlier, and indexing it by the $sortDate.
    $temp[$sortDate] = '<p> <div class="event_title"><a href=' . $feed->get_permalink(). '>'  . $item->get_title() . '</a></div> <div class="event_date"> ' . $gCalDate . '</div> <br/></p>';
}
// Change this to krsort() to display with the furthest event first.
ksort($temp);
// Loop through the (now sorted) array, and display what we wanted.
foreach (array_slice($temp, 0, 3) as $paragraph) {
    echo $paragraph;
}
?>

这个脚本获取事件标题和日期很好,它没有获取事件的公共url。相反,我看到了一个空白的日历。关于如何通过url获取公共活动信息,有什么想法吗?

要回答有关限制事件/文章的问题,请使用set_item_limit()函数。例如:

$feed->set_item_limit(5);  // limit each feed to the top 5 articles/events
$feed->init();

如果您想限制显示的总数,请使用以下选项:

$max_items_total = 25; // limit the total number of articles displayed to 25
foreach ($feed->get_items(0, $max_items_total) as $key=>$item) {
   ...
}

最新更新