Get a players Steam avatar URL

Is it possible for me to find the URL to a players avatar in gmod lua? I would like to use it for some MySQL integrated things but I can’t seem to find any way to do this.


You can use the Steam Web API.

You’ll need an API key (absolutely free, no hassle).

Assuming you have the user’s 64-bit SteamID (or have the 32-bit SteamID to convert from), you can use the GetPlayerSummaries interface like so:

You need to replace the XXXXX portion with your API key.

Here’s a working example where I use HTTP() to send a request to the API and attempt to get the full avatar URL from it:

local key = "XXXXXXXXXXXXXXXXXX" -- replace with your own from the link above

local struct = {
	method     = "get",
	failed     = function( err ) MsgC( Color(255,0,0), "HTTP error: " .. err ) end,
	url        = "",
	parameters = { key = key, streamids = "" }

function GetPlayerAvatarURL( sid64, callback )
	struct.success = callback
	struct.parameters.steamids = sid64
	HTTP( struct )

local function AvatarFromJSON( json )
	local tbl = util.JSONToTable( json )

	-- just in case something went wrong with the request
	if ( !istable( tbl ) or !tbl.response )                 then return false end
	-- most likely an invalid player was given, or they haven't set up their community profile(?)
	if ( !tbl.response.players or !tbl.response.players[1] ) then return false end
	return tbl.response.players[1].avatarfull

-- Test example using Garry's 64-bit SteamID
local function callback( code, body, headers )
	print( AvatarFromJSON( body ) )

GetPlayerAvatarURL( "76561197960279927", callback )

Hope this helps!