2010-08-22 73 views
0

我试图通过API发出调用,以便我可以删除用户属性。当我转到ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties时,它返回包含所有用户属性的XML。通过API调用获取XML

我想将该XML存储在变量$ xmlString中,然后我应该可以通过循环来获取属性并依次删除。用户属性是键和值可以是任何东西的关键值,所以不幸的是无法知道所有选项。

至今代码:

$delete = "http://www.ourwiki.com/@api/DELETE:users/$user_id/properties/%s"; 
$xmlString = file_get_contents('ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties') 
$xml = new SimpleXMLElement($xmlString); 

foreach($xml->property as $property) { 
    $name = $property['name']; // the name is stored in the attribute 
    file_get_contents(sprintf($delete, $name)); 
} 

出于某种原因,的file_get_contents似乎并不能够得到的XML。我甚至确保在环境中启用allow_url_fopen。任何帮助,这将不胜感激。

+0

难道你得到的error_reporting设为E_ALL错误/警告信息? $ xmlString('var_dump($ xmlString);')的值是什么? – VolkerK 2010-08-22 13:41:52

+0

假设我在赋值变量的地方添加var_dump($ xmlString),它返回bool(false)。 – Aaron 2010-08-22 13:53:19

回答

0

尝试

$xmlString = file_get_contents("http://ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties"); 

在第二行。在开始时不包括协议,PHP正在服务器文件系统中寻找一个文件。

编辑:

你说var_dump($xmlString)返回false。从文档:

该函数与file()相似,不同之处在于file_get_contents()从字符串中返回文件,从指定的偏移量开始直到maxlen字节。 失败时, file_get_contents()将返回FALSE。

这意味着PHP不能从GET该URL的任何数据。

尝试使用

$xmlString = file_get_contents(urlencode('http://ourwiki.com/@api/users/[email protected]/properties')); 
+0

对不起,当我写这篇文章时忽略了它,但是我在实际测试脚本时确实包含了协议。虽然似乎没有真正的效果。 – Aaron 2010-08-22 13:47:03

+0

VolkerK询问的“var_dump”的结果是什么? – 2010-08-22 13:49:20

+0

我刚刚在上面添加了一条评论,但它正在返回bool(false) – Aaron 2010-08-22 13:53:56