我試圖通過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