Tumblr XML not loading

I implemented the following code based on some code that I found in another question:
Select specific XML Tumblr values ​​using PHP

function getPhoto($photos, $desiredWidth) { $currentPhoto = NULL; $currentDelta = PHP_INT_MAX; foreach ($photos as $photo) { $delta = abs($desiredWidth - $photo['max-width']); if ($photo['max-width'] <= $desiredWidth && $delta < $currentDelta) { $currentPhoto = $photo; $currentDelta = $delta; } } return $currentPhoto; } $request_url = "http://ACCOUNT.tumblr.com/api/read?type=photo&start=0&num=30"; //$request_url = "tumblr.xml"; $xml = simplexml_load_file($request_url); foreach ($xml->posts->post as $post) { echo "<div class=\"item\"><a href='".$post['url']."'><img src='".getPhoto($post->{'photo-url'}, 250)."' width=\"250\" /></a></div>"; } 

This code worked very well on my development site, but when I clicked it on another server, it did not load the external XML from Tumblr ... It downloaded the local XML text just fine (commented out in the code).

I'm waiting to get credentials from a client, so I can contact support and work with them ...

At the same time, does anyone have any ideas what might cause this?
Server settings?
Missing PHP code?

+4
source share
1 answer

So, I ended up using cURL to load XML ... Here is the code that worked:

 function getPhoto($photos, $desiredWidth) { $currentPhoto = NULL; $currentDelta = PHP_INT_MAX; foreach ($photos as $photo) { $delta = abs($desiredWidth - $photo['max-width']); if ($photo['max-width'] <= $desiredWidth && $delta < $currentDelta) { $currentPhoto = $photo; $currentDelta = $delta; } } return $currentPhoto; } $url="http://ACCOUNT.tumblr.com/api/read?type=photo&start=0&num=30"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); // close curl request $xml = new SimpleXMLElement($data); foreach($xml->posts->post as $post) { echo "<div class=\"item\"><a href='".$post['url']."'><img src='".getPhoto($post->{'photo-url'}, 250)."' width=\"250\" /></a></div>"; } 
0
source

Source: https://habr.com/ru/post/1446378/


All Articles