2011-07-20 40 views
0

以下是代碼。它似乎根本不打開谷歌日曆。我相信這跟我使用的url有關,並且可能是特殊字符。我得到如下:使用php的domdocument從Google日曆獲取信息

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

<? 
$dom = new DOMDocument(); 
$feed = "https://www.google.com/calendar/feeds/[email protected]/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"; 
     } 
    } 
?> 

回答

0

據我所知,DOMDocument::loadHTMLFile()能夠協商SSL的,但如果它失敗了,您可以嘗試file_get_contents()先讀取文件轉換成字符串。

$dom = new DOMDocument(); 
$feed = "https://www.google.com/calendar/feeds/[email protected]/public/basic"; 
$feed_string = file_get_contents($feed); 
$html = $dom->loadHTMLFile($feed_string); 

雖然這是完全推測。像這樣對待它。

編輯確保allow_url_fopen已在您的php.ini中啓用。

+0

警告:file_get_contents(https://[email protected]/public/basic)[function.file-get-contents]:未能打開流:在/ home/timeline/public_html中沒有這樣的文件或目錄第4行的/getEventsFromCalendar.php當我執行您的建議更改時,我會獲得此信息。 –

+0

@joe休斯我沒有這個問題。我可以用'file_get_contents()'讀取URL,以便您可能遇到網絡問題,或者PHP無法連接到網絡。 –

+0

@joe Hughes確保'allow_url_fopen'在php.ini中打開 –

相關問題