2012-04-06 42 views
0

我正在使用Twitterbot後端應用程序,我試圖將可以保存然後閱讀的字符串中的直接消息複製。如果我想成功地將它集成到我的AIML(人造智能標記語言)引擎中。PHP SimpleXML語法錯誤

當我運行該文件來測試它,我得到一個解析錯誤:

syntax error, unexpected T_VARIABLE referring to the line "file_put_contents('Program-O/InfoBot2012/test.xml', $direct_messages);" 

我檢查語法並沒有明顯的錯誤,因爲我也跟着this線程。

$connection = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret); 

$direct_messages = $connection->get('direct_messages'); 

$direct_messages = file_get_contents('https://api.twitter.com/1/direct_messages.json') 
file_put_contents('Program-O/InfoBot2012/test.xml', $direct_messages); 

$direct_messages = simplexml_load_file("test.xml"); 

回答

1
$direct_messages = file_get_contents('https://api.twitter.com/1/direct_messages.json') 
                         ^-- 

你缺少;在我的標記點。

+0

file_put_contents不需要「$」 – mseancole 2012-04-06 16:16:55

+0

你好,我加了;和$的建議,但現在我得到更多的錯誤: 「警告:file_get_contents()[function.file-get-contents]:無法找到包裝」https「 - 你忘了啓用它時,你配置PHP 「和」警告:file_get_contents(https://api.twitter.com/1/direct_messages.json)[function.file-get-contents]:未能打開流:C:\ wamp \ www中的無效參數\ Program- O \ InfoBot2012 \ directmessage_test.php「引用$ direct_messages = file_get_contents('https://api.twitter.com/1/direct_messages.json'); – 2012-04-06 16:45:41

+0

也出現這些錯誤: 「Warning:file_put_contents(Program-O/InfoBot2012/test.xml)[function.file-put-contents]:無法打開流:C:\ wamp \ www中沒有這樣的文件或目錄\ Program-O \ InfoBot2012 \ directmessage_test.php「引用file_put_contents行('Program-O/InfoBot2012/test.xml',$ direct_messages); 和「Warning:simplexml_load_file()[function.simplexml-load-file]:I/O警告:無法在C:\ wamp \ www \ Program-O \ InfoBot2012 \ directmessage_test中加載外部實體」test.xml「。 PHP「指的是代碼行$ direct_messages = simplexml_load_file(」test.xml「); – 2012-04-06 16:46:11

0

根據direct_messages api上的Twitter文檔,請求https://api.twitter.com/1/direct_messages.json將返回一個JSON響應,您試圖將其保存並加載爲XML。

嘗試用https://api.twitter.com/1/direct_messages.xml代替。

希望它有幫助。

+0

感謝您的答覆,但它不工作,通過嘗試與https://api.twitter.com/1/direct_messages.xml ...我得到相同的錯誤,因爲以前發佈... – 2012-04-06 17:05:34

1

你必須啓用php_openssl.dll(因爲你使用的是Windows的dll)。

您可以通過打開php.ini(通常是xampp/EasyPHP文件夾中的apache/bin/php.ini)來執行此操作,並刪除「;」之前的行「擴展= p​​hp_openssl.dll」(所以你取消註釋),或者將'extension = php_openssl.dll'添加到文件的底部。

這種方式php_openssl.dll將被加載,PHP將知道如何處理HTTPS。