|
Joe Casadonte
United States King of Prussia Pennsylvania
-
Updated for the new almost-RPG Geek.
For those of us updating play data programatically, you'll need to post the following data:
URL to post to: http://www.boardgamegeek.com/geekplay.php
DATA to post:
Quote: dummy=1&ajax=1&action=save&version=2&objecttype=thing&objectid=7218&playid=&action=save&playdate=2009-02-26&dateinput=2009-02-26&YUIButton=&location=&quantity=3&length=34&incomplete=0&nowinstats=0&comments=Laurel%20%26%20Hardy%20joined%20us&players[1][playerid]=&players[1][name]=Joe&players[1][username]=Joe Casadonte&players[1][color]=Blue&players[1][position]=1&players[1][score]=118&players[1][rating]=6.5&players[1][new]=1&players[1][win]=1&players[2][playerid]=&players[2][name]=Will&players[2][username]=&players[2][color]=Red&players[2][position]=1&players[2][score]=64&players[2][rating]=10&players[2][new]=1&players[2][win]=0
where:
objectid - the BGG game number playdate - the play date in YYYY-MM-DD format dateinput - today's date in YYYY-MM-DD format location - encoded string (e.g. "Jim's House" would be "Jim's%20House", without the quotes) quantity - the number of plays to record length - the length of the game in minutes comments - the encoded comments incomplete - set to '1' (without the quotes) if the game was incomplete, '0' otherwise nowinstats - set to '1' (without the quotes) to not record win stats, '0' otherwise
Player information can be added in like so (and also left off completely):
players[x][playerid] - no idea what this is players[x][name] - the player's name players[x][username] - no idea -- BGG name maybe? players[x][color] - player color players[x][position] - start position? players[x][score] - player's score players[x][rating] - players rating (presumably on a BGG scale) players[x][new] - set to '1' (without the quotes) if this player was new to the game, '0' otherwise players[x][win] - set to '1' (without the quotes) if this player won, '0' otherwise
with [x] being a sequential number (e.g. players[1][name]&players[1][color]&players[2][name]&players[2][color])
=====
First you need to set a cookie with your user ID and encoded password; in Perl, the whole transaction would look something like this:
Quote: my($ua) = new LWP::UserAgent;
my($url) = "http://www.boardgamegeek.com/geekplay.php?dummy=1&ajax=1&action=save&version=2&objecttype=thing&objectid=$data->{'BGGID'}&playid=&action=save&playdate=$data->{'PlayDate'}&dateinput=$today&YUIButton=&location=&quantity=$data->{'PlayQty'}&length=&incomplete=0&nowinstats=0&comments=";
my($req) = HTTP::Request->new(GET => $url);
my(@dateparts) = localtime(time); my($today) = sprintf('%04d-%02d-%02d', $dateparts[5]+1900, $dateparts[4]+1, $dateparts[3]);
my($cookies) = new HTTP::Cookies; $cookies->set_cookie(0, "bggusername", "Joe+Casadonte", "/", ".boardgamegeek.com"); $cookies->set_cookie(0, "bggpassword", "SOME ENCODED VALUE", "/", ".boardgamegeek.com");
$ua->cookie_jar($cookies);
my($resp) = $ua->request($req);
Where $data->{'foo'} has to be supplied by your program, and "SOME ENCODED VALUE" is the actual value of your cookie (I'll leave that exercise up to the reader).
-
Nathan Morse
United States Powell Ohio
-
For us lazy folks, here's a compilable example:
Quote: #!/usr/bin/perl
use strict; use LWP;
my($ua) = new LWP::UserAgent;
my(@dateparts) = localtime(time); my($today) = sprintf('%04d-%02d-%02d', $dateparts[5]+1900, $dateparts[4]+1, $dateparts[3]);
my $data; $data->{'BGGID'} = 41550; $data->{'PlayDate'} = $today; $data->{'PlayQty'} = 1; my $bggUserName = "You probably don't want to hard-code this."; # e.g. Joe+Casadonte my $EncryptedPasswordCookie = "Seriously, you probably don't want to hard-code this."; # e.g. AAugi7faqE3gN
my($url) = "http://www.boardgamegeek.com/geekplay.php?dummy=1&ajax=1&action=save&version=2&objecttype=thing&objectid=$data->{'BGGID'}&playid=&action=save&playdate=$data->{'PlayDate'}&dateinput=$today&YUIBut
my($req) = HTTP::Request->new(GET => $url);
my($cookies) = new HTTP::Cookies; $cookies->set_cookie(0, "bggusername", $bggUserName, "/", ".boardgamegeek.com"); $cookies->set_cookie(0, "bggpassword", $EncryptedPasswordCookie, "/", ".boardgamegeek.com");
$ua->cookie_jar($cookies);
my($resp) = $ua->request($req);
-
Joe Casadonte
United States King of Prussia Pennsylvania
-
For some reason this has stopped working for me; is it working for anyone else, still?
-
Joe Casadonte
United States King of Prussia Pennsylvania
-
I finally had a chance to try out my theory as to what was wrong, and indeed I found and fixed the issue. The GET method no longer works; you now have to use the POST method, which is just 2 extra lines of code. Here's a full example ala zefquaavius:
Quote: #!/usr/bin/perl
use strict; use LWP;
my($ua) = new LWP::UserAgent;
my(@dateparts) = localtime(time); my($today) = sprintf('%04d-%02d-%02d', $dateparts[5]+1900, $dateparts[4]+1, $dateparts[3]);
my $data = {}; $data->{'BGGID'} = 41550; $data->{'PlayDate'} = $today; $data->{'PlayQty'} = 1; my $bggUserName = "You probably don't want to hard-code this."; # e.g. Joe+Casadonte my $EncryptedPasswordCookie = "Seriously, you probably don't want to hard-code this."; # e.g. AAugi7faqE3gN
my($req) = HTTP::Request->new(POST => ' http://www.boardgamegeek.com/geekplay.php'); $req->content_type('application/x-www-form-urlencoded'); $req->content("dummy=1&ajax=1&action=save&version=2&objecttype=thing&objectid=$data->{'BGGID'}&playid=&action=save&playdate=$data->{'PlayDate'}&dateinput=$today&YUIButton=&location=&quantity=$data->{'PlayQty'}&length=&incomplete=0&nowinstats=0&twitter=0&twitter_username=&twitter_password=&comments=");
my($cookies) = new HTTP::Cookies; $cookies->set_cookie(0, "bggusername", $bggUserName, "/", ".boardgamegeek.com"); $cookies->set_cookie(0, "bggpassword", $EncryptedPasswordCookie, "/", ".boardgamegeek.com");
$ua->cookie_jar($cookies);
my($resp) = $ua->request($req);
-
Sterling Babcock
United States
Colorado
-
I keep getting "Invalid Action".
http://www.boardgamegeek.com/geekplay.php?dummy=1&ajax=1&act... &version=2&objecttype=thing&objectid=40692&playid= &playdate=2009-05-14&dateinput=&YUIButton=&location=&quantity=1 &length=&incomplete=0&nowinstats=0&twitter=0&twitter_username= &twitter_password=&comments=
-
Joe Casadonte
United States King of Prussia Pennsylvania
-
Sterling,
You can no longer do this via a GET action (passing the arguments in on the URL). It must be done as a POST action (passed in via content). Here are some links on the difference:
http://stackoverflow.com/questions/46585/when-do-you-use-pos...
http://www.cs.tut.fi/~jkorpela/forms/methods.html
-
Sterling Babcock
United States
Colorado
-
Joe Casadonte wrote: That's too bad.
I create the URL in Excel and just click on it. I did not set up a complete perl script etc. All I wanted was a link I could click to register the game. I guess that ends my logging games then.
So would I have to create a web page for each game logged? That could be hundreds of web pages. Any way to do a POST from within Excel?
-
Nathan Morse
United States Powell Ohio
-
Sterling, I wouldn't be surprised if you could do it with a macro in VBA - Excel still uses Visual Basic for Applications, right?
If you want to send me your file, I could try modding it for you. GM me if you're interested.
...or I could set up a script that takes GET-style arguments like you've done, and then POSTs it to BGG....
-
Joe Casadonte
United States King of Prussia Pennsylvania
-
zefquaavius wrote: or I could set up a script that takes GET-style arguments like you've done, and then POSTs it to BGG....
The only problem being the password that needs to be set.....
-
|
|