TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,234
  • Total Topics: 21,353
  • Online today: 639
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 216
  • Total: 216

Using APIs

Started by mrandall131, May 01, 2007, 07:39:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mrandall131

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?

eldacar

Depends entirely on each API. They could be completely different.

mrandall131

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.

mrandall131

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);

?>

JPDeni

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.

mrandall131

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"

JPDeni

It looks like you have it in a regular article and not a php article.

mrandall131

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.

vanguard

Anyone use the YouTube API?

G6Cad

mrgray, please start your own thread with your question ;)

This website is proudly hosted on Crocweb Cloud Website Hosting.