Obtaining XML through API call
I'm trying to issue a call through API so that I can delete user properties. When I go to ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties it returns the XML which includes all of that users properties.
I'm trying to store that XML in variable $xmlString then I should be able to loop through to g开发者_开发问答et the properties and in turn delete. The user properties is key value where the key and value can be anything so there is no way of being able to know all options unfortunately.
The code so far:
$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));
}
For some reason, file_get_contents does not seem to be able to get the XML. I've even made sure that allow_url_fopen is enabled in the environment. Any help with this would be greatly appreciated.
Try
$xmlString = file_get_contents("http://ourwiki.com/@api/users/=john_smith%40ourwiki.com/properties");
in the second line. By not including the protocol at the beginning, PHP is looking for a file in the servers filesystem.
EDIT:
You said var_dump($xmlString)
returns false. From the docs:
This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.
Which means PHP cannot GET
any data from that URL.
Try using
$xmlString = file_get_contents(urlencode('http://ourwiki.com/@api/users/=john_smith@ourwiki.com/properties'));
精彩评论