XF 2.2 Get user avatar URL

pupu

Member
How do third-party programs get the URL of the Xenforo user avatar?

头像.jpg



Is the default XenForo avatar also available?
In order to save database space, not all users can upload avatars.
For example this

moren.jpg
 

Brogan

XenForo moderator
Staff member
I don't really understand the question about third party programs.
What are you trying to do.

The single letters are known as dynamic avatars - that's an option in the settings.
1637161449351.png
 

Brogan

XenForo moderator
Staff member
You can use the API which will return all avatar URLs: GET users/{id}/ .

Code:
"avatar_urls": {
    "o": "https://localhost/xf/data/avatars/o/0/2.jpg?1566934356",
    "h": "https://localhost/xf/data/avatars/h/0/2.jpg?1566934356",
    "l": "https://localhost/xf/data/avatars/l/0/2.jpg?1566934356",
    "m": "https://localhost/xf/data/avatars/m/0/2.jpg?1566934356",
    "s": "https://localhost/xf/data/avatars/s/0/2.jpg?1566934356"
},

 

Brogan

XenForo moderator
Staff member
Or if you don't want to use the API, you can work it out based on the user ID.

My ID is 521.
Avatars are stored in five directories (h, l, m, o, s) numbered 0 upwards, with 1,000 files per directory, based on the user ID.

So for me, the original file would be: https://xenforo.com/community/data/avatars/o/0/521.jpg .

Your ID is 196224.
For you it is: https://xenforo.com/community/data/avatars/o/196/196224.jpg .
 

pupu

Member
Or if you don't want to use the API, you can work it out based on the user ID.

My ID is 521.
Avatars are stored in five directories (h, l, m, o, s) numbered 0 upwards, with 1,000 files per directory, based on the user ID.

So for me, the original file would be: https://xenforo.com/community/data/avatars/o/0/521.jpg .

Your ID is 196224.
For you it is: https://xenforo.com/community/data/avatars/o/196/196224.jpg .
What if it is the default avatar generated by XenForo? How to request to get it.
example this
moren.jpg
 

joszwa

Member
Or if you don't want to use the API, you can work it out based on the user ID.

My ID is 521.
Avatars are stored in five directories (h, l, m, o, s) numbered 0 upwards, with 1,000 files per directory, based on the user ID.

So for me, the original file would be: https://xenforo.com/community/data/avatars/o/0/521.jpg .

Your ID is 196224.
For you it is: https://xenforo.com/community/data/avatars/o/196/196224.jpg .
Hey Brogan,

Thanks so much for explaining this. I'm trying to retrieve a user's avatar from an external place. However I struggle to find out what the number between the size and the User ID is for, or how I know which one to use. In your first example it's /o/0/512.jpg and in your second one it's /o/196/196224.jpg. Now is there a way to know which number to use there (without being in the XenForo environment)?

Thank you!
 
Top