Jump to content

Quick question about retrieving XML data from oEmbed

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Codeturk

Codeturk

    Newbie

  • Members
  • Pip
  • 5 posts
I am trying to retrieve the XML data in order to write a very simple php script that will create .html (or output in a seperate .php) on the same directory as the script.

The idea is to gather only small part of the xml output:
<oembed>

<version>1.0</version>

<provider_name>SmugMug</provider_name>

<provider_url>http://www.smugmug.com/</provider_url>

<type>video</type>

−

<html>

<object width="640" height="480"><param name="movie" value="http://cdn.smugmug.com/ria/ShizVidz-2010102501.swf"/><param name="allowFullScreen" value="true"/><param name="flashVars" value="s=ZT0xJmk9MTAxMTYyNTgwOSZrPTl0NGRIJmE9MTM4MDY3NzBfNXRuTGgmdT1odW50c3ZpbGxlY2Fyc2NlbmU="/><embed src="http://cdn.smugmug.com/ria/ShizVidz-2010102501.swf" flashVars="s=ZT0xJmk9MTAxMTYyNTgwOSZrPTl0NGRIJmE9MTM4MDY3NzBfNXRuTGgmdT1odW50c3ZpbGxlY2Fyc2NlbmU=" width="640" height="480" type="application/x-shockwave-flash" allowFullScreen="true"></embed></object>

</html>

<duration>116</duration>

<height>480</height>

<width>640</width>

<author_name>huntsvillecarscene</author_name>

<author_url>http://newpics.huntsvillecarscene.com/</author_url>

</oembed>

URL of above xml is:
http://api.smugmug.c...011625809_9t4dH

And I am trying to get only the <html> </html> element saved in a new .html file
I tried using
xmlhttp.open("GET","http://api.smugmug.com/services/oembed/?url=http%3A%2F%2Fnewpics.huntsvillecarscene.com%2FHuntsville-Car-Scene%2FEvents%2FFirst-Look-2011-Audi-A8-and/13806770_5tnLh%231011625809_9t4dH",false);

but this doesn't seem to work, or I could not get it to work.
Any ideas?

I would have a file called createpage.php
with
Enter Url: Text Field for URL
Enter Page name: [pagename] Text field for name of the .html to be created
[Submit]

This would then output pagename.html
with only <html> </html> element of the xml given.

#2
Codeturk

Codeturk

    Newbie

  • Members
  • Pip
  • 5 posts
Update: I fiddled with the code, and I realized that xmlhttp.open does not work (or does not allow) to retrieve data from XML located in another server.
Therefore I cannot use xmlhttp in a script located in 111111.com to get data from a xml located in 22222.com

So in order to test this, I placed both XML and xmlhttp script in same directory.

http://www.dsblogs.c...smugmug.com.xml (copy of source data that actually resides in another server)
http://www.dsblogs.c...cal_oembed.html

the XML is actually going to be coming from the link I gave above, spitted out by oEmbed.

The first step to achieving what I want to do is to find a way to get only the embed code from oEmbed output.

#3
grisha

grisha

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Did you try to use DOMDocument or SimpleXML classes available in PHP? I use those two in most of my XML work using PHP.

#4
Codeturk

Codeturk

    Newbie

  • Members
  • Pip
  • 5 posts
I posted a reply to update my original post, but it still did not appear here.
Thanks for the suggestion, do you have a sample I could try to base mine on? I am really not familiar with php/xml programming as I am a VB6+ man myself.

I already was able to get the data I needed using following and it works well,
however there is one huge limitation xmlhttp.open("GET" does not work across remote servers, it only works if both XML and the HTML running xmlhttp.open are on the same folder on same server.

Here is the working code (locally only) which I need to turn into working code remotely to grab data:



<html>

<body>


<script type="text/javascript">

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttp.open("GET","oEmbed.api.smugmug.com.xml",false);

xmlhttp.send();

xmlDoc=xmlhttp.responseXML; 


document.write("<table border='1'>");

var x=xmlDoc.getElementsByTagName("oembed");

for (i=0;i<x.length;i++)

  { 

  document.write("<tr><td>");

  document.write(x[i].getElementsByTagName("author_name")[0].childNodes[0].nodeValue);

  document.write("</td><td>");

  document.write(x[i].getElementsByTagName("html")[0].childNodes[0].nodeValue);

  document.write("</td></tr>");

  }

document.write("</table>");

</script>


</body>

</html>








1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users