Reputation: 43
I've been trying to parse odata's xml and json data with simplexml and json_decode, and it's not working. I'm getting useless data back, when I query for data and place the link in the address bar I can see the data I want in there. When I place the link in a simplexml or json_decode method and do a var_dump(), none of the data is in there.
It's just a bunch of odata links, to get the data. For example,
My original link, domain.com/1.0/DataService/Titles(4563)/?devid={...}.
This data will show the genre, title, and description, but inorder for me to get the Genre or Description, I will need to use this url which is,
domain.com/1.0/DataService/Genre(4563)/?devid={...} or domain.com/1.0/DataService/Description(4563)/?devid={...}.
If using the oData SDK makes it easier to get the data, that's great, but I've read the SDK installation located here, http://odataphp.codeplex.com/. I'm just not sure where to begin with it.
EDIT
Here's some sample code
$url = "http://api.internetvideoarchive.com/1.0/DataService/EntertainmentPrograms()?$expand=MovieCategory,Director,Copyrightholder&$select=MovieCategory/*,Director/*,Copyrightholder/*&developerid=bafd5091-a36d-4103-b435-638dc55d2122&format=atom";
$xml = simplexml_load_file("$url");
var_dump($xml);
You can change atom to json to get the json data.
Upvotes: 0
Views: 1076
Reputation: 4555
The problem in your sample code is the double quotes when defining $url. PHP will try to interpolate $expand, $select, etc. as variables. Since they don't exist as variables in your code, they will just be removed.
The result of this is that you lose the $expand in the url, which will make MovieCategory and the other navigation links show up just as URLs to the data instead of including the data inline.
Use single quotes instead:
$url = 'http://api.internetvideoarchive.com/1.0/DataService/EntertainmentPrograms()?$expand=MovieCategory,Director,Copyrightholder&$select=MovieCategory/*,Director/*,Copyrightholder/*&developerid=bafd5091-a36d-4103-b435-638dc55d2122&format=atom';
$xml = simplexml_load_file($url);
var_dump($xml);
Upvotes: 1