2012-04-06 49 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。