Massimiliano della Rovere
Italy
Pisa
Tuscany
flag msg tools
badge
Avatar
mbmbmbmbmb
Hi, I am writing a few php scripts to help my gaming group during the hard question: "today we need a X-player game lasting more or less X minutes. Which game of ours fits into these guidelines?"

The whole system uses the "export collection" facility:
the collection is downloaded, optionally merged with other ones, then the user can query a game by time length,min or max numeber of players, and so on.
the output is shown using a table, with links to the game page on the bgg site.

Now, I have two small questions: here on bgg is there a cgi that accepts

- as parameter a gameid and feeds the representative image for that game?
something like http://images.boardgamegeek.com/representative.js?gameid=300

- as parameter an user name and the fields, and then exports the user's game collection (this means only owned games)?

thanks
 
 Thumb up
 tip
 Hide
  • [+] Dice rolls
Kevin McKenzie
United States
Garland
Texas
flag msg tools
badge
Avatar
mbmbmbmbmb
The two ways I know of to export ones collection is the Export option on your collection screen and the XMLAPI interface described at http://www.boardgamegeek.com/xmlapi/

In the XML Interface you can return your collection but I do not see the representative image as one of the returns...... yet anyway

Good luck.
 
 Thumb up
 tip
 Hide
  • [+] Dice rolls
Massimiliano della Rovere
Italy
Pisa
Tuscany
flag msg tools
badge
Avatar
mbmbmbmbmb
Yes, at least the representative image should be retrievable.

Below there is a little excerpt from my php script to retrieve my collection together with game infos.

BGG is *really* slow with the xml interface, and I need at least 10 seconds for the second fetch. Is there a way speed up my code?

function get_collection( $user )
{
$ch = curl_init( "http://www.boardgamegeek.com/xmlapi/collection/" . $user );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
$xmldata = curl_exec( $ch );
curl_close( $ch );

$xml = new XMLReader();

$xml->XML($xmldata);
$data = array();
$index = array();
$games = "";
$i = 0;

while ($xml->read()) {
if( !strcmp( $xml->name, "game" ) && ($xml->nodeType==1) ) {
$xml->moveToAttribute ( "gameid" );
$games .= $xml->value . ",";
$index[$xml->value] = $i;
$data[$i]["gameid"] = $xml->value;
$xml->moveToAttribute ( "name" );
$data[$i]["gamename"] = utf8_encode( $xml->value );
$xml->moveToAttribute ( "rating" );
$data[$i]["quickrating"] = $xml->value;
$i++;
}
}
$games = substr( $games, 0, strlen($games)-1 );

$ch = curl_init( "http://www.boardgamegeek.com/xmlapi/game/" . $games );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
$xmldata = curl_exec( $ch );
curl_close( $ch );


$xml->XML($xmldata);

while ($xml->read()) {
switch( $xml->depth ) {
case 0: continue;
case 1: if( !strcmp( $xml->name, "game" ) && ($xml->nodeType==1) ) {
$xml->moveToAttribute( "gameid" );
$i = $index[$xml->value];
}
break;
case 2: if( !strcmp( $xml->name, "minplayers" ) ||
!strcmp( $xml->name, "maxplayers" ) ||
!strcmp( $xml->name, "playingtime" ) ) {
$tag = $xml->name;
$xml->read();
$data[$i][$tag] = $xml->value;
$xml->read();
}
break;
} //switch
} //while

return array( $data, $index );
}
 
 Thumb up
 tip
 Hide
  • [+] Dice rolls
Front Page | Welcome | Contact | Privacy Policy | Terms of Service | Advertise | Support BGG | Feeds RSS
Geekdo, BoardGameGeek, the Geekdo logo, and the BoardGameGeek logo are trademarks of BoardGameGeek, LLC.