This is probably the biggest update to the API since it was introduced. Scratch that, this is the biggest update. Most of the changes have been structural. I have created several classes for different content types, split classes into their own files and created a proper class hierarchy. As far as usable features, I added award information (ribbons and medals) and server information. An unfortunate side effect of the cached language file (used for ribbons, medals, etc) is that the size of the API has increased from 5KB to 153KB (zipped sizes), but I think a larger file size is better than querying Battlelog for the language file every time (though the API allows you to so that too, albeit experimentally).
Hit up the project page for more information and the download link. Let me know if there are any issues with this release.
Small warning: When getting friends data (by invoking $soldier['friends']), note that the ID is not the nine-digit soldier ID. It is the main Battlelog user ID. I will be working on a way to remedy this situation if possible.
Comments
Thanks so much for putting together such a wonderful and well organized API for BF3! You mention above that the ID is NOT the 9 digit soldier ID, but rather the ID that you can see in the URL when viewing a player’s stats page. This number also appears to be 9 digits long.
I wanted to see if there is an easy way to tell what is the actual Battlelog user ID opposed to the Soldier ID. As of right now, I am getting a 500 error with ‘Invalid soldier data’ as the message in my error log.
I double checked that I have PHP with cURL enabled, so I am not sure what else could be the issue. Thanks again!
@Rich, double check that your session cookie is being created, without it, you cannot query any soldier or server stats. Here’s some instructions:
http://www.blakeharley.com/2011/10/battlelog-api-1-2-1-pre/
Thanks so much for your help, I got this up and running now, it works awesome! Please let me know if there is anything that I can do to contribute to the project.
Dude you rock. Thx for the major update.
I’ll share my work soon.
@rich Artax helped me on this one asswell look at the comments on version 1.2.1. this API keeps growing
awesome work!!
Thanks for pointing me in the right direction, that saved me a ton of time and was a super quick fix. Should have guessed it was something as simple as cookies.
nice work..
but is there no way to get this data without a battlelog login?
i dont want to risk my acc to be deletet due to reading stats for all my friends and publish it on our site
Unfortunately, no. Not at this time. I was hoping they would make stats public after the beta ended, but I guess that wasn’t the plan.
I wouldn’t be surprised that after the dust settles from launch, they’ll release an API of sorts.
No idea, i mailed EA about it, but they have no clue what i asked.
They could only help me with the game, not with website related things.
i added mapMode below of map in the serverClass
‘mapMode’ => BF3Server::mode($data['mapMode']),
or was it accessible in an other way?
I forgot to put that in, thanks for catching that.
Nice work so far, but is there a way to connect through this API with my user and to appear as I’m connected online to a server?
I know this is not very legal but I was just wondering if it’s possible.
Or do you have any advice on how to do this?
Thanks
Getting a weird error when trying to request PS3 users. The example ID worked all well and good, but as soon as I replace with any PS3 user’s ID (I’ve tried 174501052 and 234040474), I wind up getting:
PHP Notice: Undefined index: awards in /opt/www/test/BF3Soldier.class.php on line 279
PHP Fatal error: Uncaught exception ‘BattlelogException’ with message ‘Invalid awards data’ in /opt/www/test/BF3Soldier.class.php:281
Stack trace:
#0 /opt/www/test/BF3Soldier.class.php(353): BF3Soldier->getAwards()
#1 /opt/www/test/BF3Soldier.class.php(378): BF3Soldier->get(‘ribbons’)
#2 /opt/www/test/test.php(6): BF3Soldier->debugData()
#3 {main}
thrown in /opt/www/test/BF3Soldier.class.php on line 281
shell returned 255
Any ideas?
It looks like console players have their console name appended to the awards URL (eg, PS3 user’s stats URLs end with “ps3″).
I’ll look into fixing that.
As an FYI, that was using var_dump($soldier->debugData()), I noticed that with doing a basic print_r() function on $soldier also resulted in not pulling the stats. All I would get for my queries was their name, everything else would return 0′s. Digging a bit further, I noticed that viewing the source, on line 364, it would read: where the 4th value could be an variation of bf3-country-kit. If going with your idea of None, as long as the final value is 4 instead of 1, at least with the couple that I checked, it would work. Not certain as to the difference in the final value, but it seems significant enough.
Sorry, silly me included the div tag, thus getting it cut out by the filter when posting. on line 364, the URL path was similar to: /bf3/overviewPopulateStats/[[ID]]/bf3-us-support/4/
I already know the URL structure. “bf3-us-support” is the user icon that gets displayed on the stats page. I leave that to “None” because it’s not necessary for this API.
The number at the end is the platform int. 1 being PC, 2 is for Xbox and 4 is for PS3.
The problem is trying to find out what platform a given soldier ID is supposed to be tied to. At the moment, this seems impossible without getting the main user data.
Blake, do you know how to fix the xbox 360 issue for the soldier when I manualy typ in the player´s console? Because you said you know 2 is for xbox.
cool the server part works like a charm. is it possible to diplay user status on bl this is done with a color on the avatar picture green blue and grey.
The list itself looks like it displays all players that where in that specific round.Because sometimes it displays more players then there are server slots available
I looks like there are 3 stages online on server, online on battlelog and offline. Also on soldier will a full weapons stats be feasible
as well ?
awesome work sofar!!!!
Any change of putting this up on GitHub?
I’ve added a function to pull in Map images (well at least one size, not sure of what the other sizes are yet if there are any) and I’ve also started working on a Platoon class.
I’d contribute some.
Hi,
thank you very much for this awesome code!
I´m just getting an error on my site :
Fatal error: Uncaught exception ‘BattlelogException’ with message ‘Invalid soldier data’ in BF3Soldier.class.php:75 Stack trace: #0 BF3Container.class.php(114): BF3Soldier->_parseData(‘{“partial”:fals…’) #1 BF3Container.class.php(76): BF3Container->_load() #2 BattlelogApi.inc.php(129): BF3Container->__construct(Object(BattlelogApi), ’123456789′, true)
Version: 1.3
yesterday it worked fine. did dice/ea change anything?
Hi Guys,
changing the cookie path made it. Im sorry.
anyone got a decent way to print out the players on a server, without the [3] array tags, just the plain text.
Been looking over it for a few days and cant seem to find it.
my current progress:
http://crab-studio.eu/server/server.php?server-id=93853c14-71e4-4be5-bf25-840b10ef6712
Hi Blake, I was trying to retreve rank from this profile
http://battlelog.battlefield.com/bf3/soldier/P1mpKill3r/stats/341583534/
(Probberly a cheater, dont know) but then I try that, it get the wrong image for that rank in rankimage url
//Kind regards
thank you so much for creating this! I am currently trying to transfer this to asp and was wondering if anyone could post(with fake data of course) what the final url you send to login looks like?
I appreciate it
Thanks for this! It’s awesome, already have a nice little personal mobile site up wich I use when playing and don’t want to go to my computer to check my stats out (:
I bet you’re already working on this, but I though I’d just mention a couple of things I’m really missing:
-Score achieved on current rank
-Score needed for current rank
-Score left until rankup
-Next unlock and score achieved / left for kits, rank and vehicles
Can’t say that there is much more that’s essential (in my case)
What is “pointsNeeded” by the way? Mine say 280 000. That much points needed until, what? /:
Oh and yeah: Why is login needed? Many apps out there wich don’t use it (android) and why can’t you use username instead of userID (like apps out there do).
Thanks again, keep up the good work!
Is there any way to get a JSON output of a specific Battle Report?
Excellent, well thought-out API, thank you.
Getting the nine-digit soldier IDs for friends would be a major upgrade and my only wish for improvement so far.
Thanks again.
Hey Blake,
Nice library.
In the Utilities class you can lookup ranks, but it stops at rank 45 because after that the URL changes to: Anyone seen this rank on the battlefields yet? Legit? http://battlelog-cdn.battlefield.com/public/profile/bf3/stats/ranks/medium/ss1.png up to ss100. Might wanna tweak that!
Keep it up!
Hey Gerben,
my workaround for this problem is (see BattlelogAPI.inc.php; search public static function getRankImage($rank, $size = ‘small’) ):
public static function getRankImage($rank, $size = ‘small’)
{
$validSizes = array(‘tiny’, ‘small’, ‘medium’, ‘large’);
$size = strtolower($size);
if (!in_array($size, $validSizes))
{
throw new BattlelogException(“Invalid size ‘$size’ specified”);
}
if ($rank>=’46′) {
for ($i=0;$i<=100;$i++) {
if ($rank==$i) {
$rankimgcache = $rank-45;
$rankimg = "http://battlelog-cdn.battlefield.com/public/profile/bf3/stats/ranks/$size/ss$rankimgcache.png";
break;
}
}
} else {
$rankimg = "http://battlelog-cdn.battlefield.com/public/profile/bf3/stats/ranks/$size/r$rank.png";
}
return $rankimg;
}
blame on me! it´s very bad code but solved the problem until the next version will release!
WTF?
…
if ($rank > 45)
return “http://battlelog-cdn.battlefield.com/public/profile/bf3/stats/ranks/$size/ss”.($rank – 45).”.png”;
else
return “http://battlelog-cdn.battlefield.com/public/profile/bf3/stats/ranks/$size/r$rank.png”;
…
Hi,
it seems that since the update today the cookies are not needed to fetch the JSON data from Battlelog. Any chance you could update the API?
And I was wondering if you had time to check out whether there’s a way to determine the friend’s nine-digit ID.
Thanks!
@Nick,
Here’s a How To to get your nine-digit ID:
http://www.bfclanwars.com/2011/11/02/getting-bf3-player-ids-and-registering/
To get a friends ID, go to a friend’s stats page by first clicking their name. Then click their name again that is next to their Rank and Dog tags. Now you’ll see their Stats & Progression and so on, should should now be able to follow the second half of the tutorial and get your friends ID from the URL of the webpage.
Thanks Artax! I was hoping to do this through the API, rather than having to scrape the pages. But I guess this is the only way to do it for now…
Hi@,
it seems that something has changed with the Battlefield 3 Update…
We get this error while getting the server data:
Fatal error:
Uncaught exception ‘BattlelogException’ with message ‘Invalid server data’ in /home/USER/domains/DOMAIN.com/public_html/page/inc/BF3Server.class.php:50
Stack trace:
#0 /home/USER/domains/DOMAIN.com/public_html/page/inc/BF3Container.class.php(114): BF3Server->_parseData(‘{“partial”:fals…’)
#1 /home/USER/domains/DOMAIN.com/public_html/page/inc/BF3Container.class.php(76): BF3Container->_load()
#2 /home/USER/domains/DOMAIN.com/public_html/page/inc/BattlelogApi.inc.php(143): BF3Container->__construct(Object(BattlelogApi), ‘af8aee66-10f6-4…’, true)
#3 /home/USER/domains/DOMAIN.com/public_html/page/server.php(21): BattlelogApi->getBF3Server(‘af8aee66-10f6-4…’)
#4 /home/USER/domains/DOMAIN.com/public_html/page/index.php(5): include(‘/home/k106614/d…’)
#5 {main} thrown in /home/USER/domains/DOMAIN.com/public_html/page/inc/BF3Server.class.php on line 50
What is wrong there?!
yeah. EA Told, that the stats are now accessible without a login, so the script should now be possible without an ea account.
ah okay. does anybody know how to fix that? i try to get a solution maybe someone else is faster than me
okay strange result. on my localhost (XAMPP) it works perfectly but on my host the api returns me the same error as in another post here: http://www.blakeharley.com/2011/10/battlelogapi-v1-3/#comment-138
Okay, i found the error… If I try it on localhost, it creates the cookie-file in my xampp directory. on my webserver it can’t write this cookie-file.
here my work-around:
1. Open “BattlelogApi.inc.php” and look for line 34.
Change it from:
“define(‘BLA_COOKIE_FILE’, ‘cookies.txt’);”
to
“define(‘BLA_COOKIE_FILE’, ‘./temp/cookies.txt’);”
2. Create an Folder named “temp” in your root directory with the CHMOD ’777′.
3. Open your “Server-Info-Page” once. (The API should have placed a file with the name “cookies.txt” in the temp folder)
4. Check if the cookies.txt was placed in the temp folder.
5. Change the CHMOD of the temp to ’755′
6. That’s it!
Is it maybe possible to get the image of a current map that is playing on the server?
And is there data available to get the team(US/RU) the player is in when getting the playerslist?
Thanks for writing this API, very nice!
Great work! I was able to build a G15 Keyboard Applet with your API. One thing that would be a nice to have is the score till rank up. Here is a photo of what I accomplished using your API… thanks!
https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/384113_10151006054465221_736060220_21940808_526768123_n.jpg
bonjour,
S’il vous plaît, vous pouvez libérer votre G15 applet pour BF3?
Je serai vraiment heureux si vous pouvez la partager avec les joueurs qui ont un clavier G15 ..
J’espère que vous accepterez, Zach, thx à l’avance …
À bientôt
hello,
Please, you can release your g15 applet for BF3?
I’ll be really happy if you can share it with players that have a g15 keyboard ..
I hope you will accept, Zach, thx in advance …
See you soon
Hello friend, is it possible, you get a script in php stats Battlefield 2 and Battlefield: Bad Company 2?
I’ma member of a clan of fanatical battlefields, and would like to put the performance of the three platforms in our site like development.
Thanks for your attention.
http://www.battlefield.ea.com/battlefield/bf2/
http://www.battlefieldbadcompany2.com/login
Hi,
i have a problem to fetch PS3 player data.
it is possible now to parse PS3 player stats?
thx
Thanks for the awesome API!
I seem to only get 0 as a result for most requests though, the only ones that work are ID and Name. Am I doing something wrong?
Hi Blake.
Just wanted to ask if my e-mail of 29 January 2012 has arrived. Is it?
Problem:
But the charge time for more than 100 members has taken far too long.
About 40 seconds to load, so
$soldier['name'];
$play_status = $soldier['user']['presence']['isPlaying'];
$rankimages = $soldier['rankImage']['tiny'];
are completely loaded.
Jack
Hi.
Another problem:
Notice: Undefined index: isOnlineOrbit
$isOnline = $soldier['user']['presence']['isOnline']; works
$isOnlineOrbit = $soldier['user']['presence']['isOnlineOrbit']; does not work
$isPlaying = $soldier['user']['presence']['isPlaying']; works
foreach($data['profileCommon']['user']['presence'] as $k => $v)
{
if ($k != ‘userId’)
{
$this->_user['presence'][$k] = $v;
}
}
Where is the problem?
API FEATURE REQUEST:
Hi, ended up here because I was Googling for a way to automate the sending of a message via Battlelog. I want to add an in-game command for players on our server (via a PRoCon plug-in) to page an admin and figured BL would be the best way to immediately reach those who might be able to respond (even if they don’t have PRoCon running). When you’ve run out of other stuff to do…
Hello. Get answers here?
Hi there, is this still being supported?
Leave a Reply