使用php的domdocument从Google日历中获取信息

时间:2011-07-20 01:55:10

标签: php google-calendar-api domdocument

以下是代码。似乎根本没有打开谷歌日历。我相信这与我正在使用的网址有关,可能与特殊字符有关。我得到以下内容:

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/public/basic" on line 4

<?
$dom = new DOMDocument(); 
$feed = "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/public/basic";
$html = $dom->loadHTMLFile($feed);
$dom->preserveWhiteSpace = true;
$entries = $dom->getElementsByTagName("entry"); 


foreach ( $entries as $entry ) 
{ 

    $status = $entry->getElementsByTagName( "eventStatus" ); 
    $eventStatus = $status->item(0)->getAttributeNode("value")->value;

    if ($eventStatus == $confirmed) 
 {
        $titles = $entry->getElementsByTagName( "title" ); 
        $title = $titles->item(0)->nodeValue;

        $times = $entry->getElementsByTagName( "when" ); 
            $startTime = $times->item(0)->getAttributeNode("startTime")->value;
            $when = date( "l jS \o\f F Y - h:i A", strtotime( $startTime ) );

            $places = $entry->getElementsByTagName( "where" ); 
            $where = $places->item(0)->getAttributeNode("valueString")->value;

            print $title . "\n"; 
            print $when . " AST\n"; 
            print $where . "\n"; 
            print "\n"; 
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

据我所知,DOMDocument::loadHTMLFile()能够协商SSL,但如果失败,您可以尝试file_get_contents()将文件首先读入字符串。

$dom = new DOMDocument(); 
$feed = "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/public/basic";
$feed_string = file_get_contents($feed);
$html = $dom->loadHTMLFile($feed_string);

但这完全是推测性的。这样对待它。

编辑确保您的php.ini中已启用allow_url_fopen