我试图通过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。任何帮助,这将不胜感激。
难道你得到的error_reporting设为E_ALL错误/警告信息? $ xmlString('var_dump($ xmlString);')的值是什么? – VolkerK 2010-08-22 13:41:52
假设我在赋值变量的地方添加var_dump($ xmlString),它返回bool(false)。 – Aaron 2010-08-22 13:53:19