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.

http.Fetch(“steamcommunity.com/profiles/123123123123?xml=1

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:
http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXX&steamids=76561197960435530

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        = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/",
	parameters = { key = key, streamids = "" }
}

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

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
end



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

GetPlayerAvatarURL( "76561197960279927", callback )

Hope this helps!