Ok, I beling to a couple sites that have APIs all set for me to pull info from. Has anyone had experience with them? I haven't tried yet, but would like to learn. Got any good sites to reference on how to handle info with respect to APIs?
Depends entirely on each API. They could be completely different.
For example, http://www.360voice.com/api/games-listfav.asp?tag=muddyeiger&num=10&sort=3 is one of the APIs I'd like to use in an article/block on my gaming site.
Better yet, this is the test code that works when it's in a block, but doesn't when in an article. Must be the quotes vs apostrophe?
Quote from: code
<?php
$name_v = array();
$points_v = array();
$tag = "MuddyEiger";
$file = "http://www.360voice.com/api/games-listfav.asp?tag=MuddyEiger&num=10";
$open = $file;
if (!($xml = domxml_open_file($open,
DOMXML_LOAD_PARSING + //0
DOMXML_LOAD_COMPLETE_ATTRS + //8
DOMXML_LOAD_SUBSTITUTE_ENTITIES + //4
DOMXML_LOAD_DONT_KEEP_BLANKS
,$error))) {
echo "Document Could not be Read.
".$file."
".$tag."
";
exit;
}
$xmldoc = domxml_open_mem($xml,
DOMXML_LOAD_PARSING + //0
DOMXML_LOAD_COMPLETE_ATTRS + //8
DOMXML_LOAD_SUBSTITUTE_ENTITIES + //4
DOMXML_LOAD_DONT_KEEP_BLANKS
);
$elements = $xml->get_elements_by_tagname("game");
for($i = 0; $i < count($elements); $i++) {
$element = $elements[$i];
$child = $element->first_child();
while($child) {
if ($child->tagname == 'name') { $name_v[] = $child->get_content(); }
if ($child->tagname == 'currentgs') {$points_v[] = $child->get_content(); }
if ($child->tagname == 'totalgs') {$totals_v[] = $child->get_content(); }
if ($child->tagname == 'tile') {$tiles_v[] = $child->get_content(); }
$child = $child->next_sibling();
//echo $child->tagname . "
";
}
}
echo $name_v[0];
echo "
<img src='".$tiles_v[0]."'>";
xml_parser_free($xmldoc);
?>
Quotethis is the test code that works when it's in a block, but doesn't when in an article
You don't say how it doesn't work, which makes it pretty difficult to figure out what the problem is. However, the obvious thing is that you start with
<?php
and end with
?>
You have to remove those, for both blocks and articles.
Ok, for both, I have those removed. I'll leave the article up and running on my site, www.KillingAuthority.com You can see the article "Test" at the top of the main page. That's obviously wrong. It should look like the block on the right column, last one, titled "MuddyEiger's Top 10 Games"
It looks like you have it in a regular article and not a php article.
Yeah, that's what I thought too, but in the article manager, it has "PHP" next to it in parenthesis. Is it possible that it's not recognizing it as PHP for some other reason?
[edit]
Took a snapshot of the article in the manager, here it is.
Anyone use the YouTube API?
mrgray, please start your own thread with your question ;)
mrandall131, just to be sure about your article type, delete the article you have and create a new one, being sure that you create a php article from the start. Sometimes there are problems when you start with an html article and then switch to a php article.
If you still have problems, someone else will try to figure it out with you.
Ok, just did that. Deleted the article, went into the article manager, clicked add php, added a title, pasted this code into it
define('XML_DECLARATION', '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n");
$name_v = array();
$points_v = array();
$tag = "MuddyEiger";
$file = "http://www.360voice.com/api/games-listfav.asp?tag=MuddyEiger&num=10";
$open = $file;
if (!($xml = domxml_open_file($open,
DOMXML_LOAD_PARSING + //0
DOMXML_LOAD_COMPLETE_ATTRS + //8
DOMXML_LOAD_SUBSTITUTE_ENTITIES + //4
DOMXML_LOAD_DONT_KEEP_BLANKS
,$error))) {
echo "Document Could not be Read.<br />".$file."<br />".$tag."<br />";
exit;
}
$xmldoc = domxml_open_mem($xml,
DOMXML_LOAD_PARSING + //0
DOMXML_LOAD_COMPLETE_ATTRS + //8
DOMXML_LOAD_SUBSTITUTE_ENTITIES + //4
DOMXML_LOAD_DONT_KEEP_BLANKS
);
$elements = $xml->get_elements_by_tagname("game");
for($i = 0; $i < count($elements); $i++) {
$element = $elements[$i];
$child = $element->first_child();
while($child) {
if ($child->tagname == 'name') { $name_v[] = $child->get_content(); }
if ($child->tagname == 'currentgs') {$points_v[] = $child->get_content(); }
if ($child->tagname == 'totalgs') {$totals_v[] = $child->get_content(); }
if ($child->tagname == 'tile') {$tiles_v[] = $child->get_content(); }
if ($child->tagname == 'percentcomplete') {$complete_v[] = $child->get_content(); }
$child = $child->next_sibling();
//echo $child->tagname . "<br />";
}
}
for($i = 0; $i < count($elements); $i++) {
echo $name_v[$i];
echo "<br /><img src='".$tiles_v[$i]."'>";
echo "<br />Current Score: ".$points_v[$i]."/".$totals_v[$i];
echo "<br />Percent Complete: ".$complete_v[$i]."<br /><br />";
}
xml_parser_free($xmldoc);
and this is what the article looked like on the front page.
Now delete the code. Save the page. Paste the code in again. Save it again. See what happens.
That's the last thing that I can think of.
Tried, about 5 times so far. For some reason, it's not seeing it as PHP. For now, I created a blank article. Then, I created a block with the PHP in it, as it works in a block. Then, I made the block display when the blank article is clicked on. Round about way, but at least it does what I need it to.
http://www.killingauthority.com/index.php?page=13