jamiebicknell / Minecraft-Avatar

PHP script (using GD) to generate avatar or skin from a Minecraft username
MIT License
116 stars 34 forks source link

Mojang have change their Skin API #10

Open DevilishDante opened 6 years ago

DevilishDante commented 6 years ago

Hello, mojang has recently changed their skin api and this made your skin viewer no longer works. indeed the link "http://skins.minecraft.net/MinecraftSkins/DevilishDante" seems broken I try to repair but my knowledge is limited in this regard, can you please have a look, thank you in advance, DevilishDante

PS: sorry for my bad english I hope you can understand me, I used google translate to write to you ^^

jamiebicknell commented 6 years ago

Hello @DevilishDante

Thanks for bringing this to my attention. I will investigate and update you.

DevilishDante commented 6 years ago

Hi @jamiebicknell 👍 thanks for the support

Naxdy commented 6 years ago

There is a way to get the minecraft skin nowadays.

The URL https://sessionserver.mojang.com/session/minecraft/profile/<uuid> will return a json array with one of the variables being the player's skin URL. Well, almost.

For example, the output of https://sessionserver.mojang.com/session/minecraft/profile/d9df784cd7b74f218bd472ad9214117d (my character's URL) is

{"id":"d9df784cd7b74f218bd472ad9214117d","name":"xNaxDy","properties":[{"name":"textures","value":"eyJ0aW1lc3RhbXAiOjE1MTkyMDI5NzM1MTgsInByb2ZpbGVJZCI6ImQ5ZGY3ODRjZDdiNzRmMjE4YmQ0NzJhZDkyMTQxMTdkIiwicHJvZmlsZU5hbWUiOiJ4TmF4RHkiLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMmE1ZDNkOTY1Yjk1ODk1Njc5M2NjOGM2NjA4NjhkZDY5OTNiZDc5NTRhZTM1NGU2MGU4ZWY1N2UxYzY2ODM4In19fQ=="}],"legacy":true}

(note that you have to remove all hyphens from the UUID, else it will throw an error)

Decoding the Base64 string yields:

{"timestamp":1519202973518,"profileId":"d9df784cd7b74f218bd472ad9214117d","profileName":"xNaxDy","textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/2a5d3d965b958956793cc8c660868dd6993bd7954ae354e60e8ef57e1c66838"}}}

And the referenced URL leads indeed to my skin. It's a little annoying that they've changed this without any announcement.

More info can be found here: http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape

jamiebicknell commented 6 years ago

Hi @xNaXDy

Thanks for collating the info for the API. I've looked at using this in the past, but the only issue I haveis the API limits which are currently 600 requests per 10 minutes.

As each avatar would require 2 API calls (one to convert the username to UUID, then one to get the skin from the UUID it means 300 avatars per 10 minutes.

For most use cases this is no issue, I can build in server side caching to store the UUID and then that can at least reduce the API call by 1, and then cache the actual skin too. The issue would come if this script was used in a forum, where each page has 20 avatars to fetch, it will soon use up the API limit regardless of caching.

Perhaps a better direction would be to turn this into a hosted service instead of a standalone script, then it can save the username -> UUID conversions for a longer period and everyone using the service can benefit from the saved lookups. Using a database will be quicker than to have any flat file storage (as being a 'drop in' script in order to keep it simple to set up it would have to use flat file).

I do own http://www.minecraftavatar.com and have been toying with the idea of having this as a hosted service for a while yet. The only reason I haven't yet is that I don't want to be end with a hosting bill due to the amount of traffic it could potentially consume.

Naxdy commented 6 years ago

If you're assuming a forum listing avatars on a page, nowadays you can also assume that that forum has stored the Minecraft users' UUIDs, since usernames are no longer unique/can be changed. Therefore I doubt that anyone would be forced to actually convert the username to UUID (though I would probably leave the functionality in for backwards compatibility, but perhaps deprecate it).

The most efficient way would probably be storing the images server side, but seeing that different web service providers allow different permissions for php scripts (e.g. some don't allow the automatic writing of files), that would probably be best left for the user. I could imagine a function for outputting the cached image data would be useful though, so people can choose where to save it themselves (or whether to save it at all), be it a file or a database entry.

Then they can perform a check manually, if a cached version exists and isn't too old, load that instead. Otherwise fetch new image.

balex25 commented 6 years ago

Hi,

I try to use this script with local skin images, I edit in skin.php on $ch = curl_init to local/skin/user.png; but not work.

So, the skin file is already on the host, as I don't need to use API anymore.

Any help is appreciated, thank!

jamiebicknell commented 6 years ago

@balex25 If you're using a relative/absolute path instead of a URL, then I'd suggest file_get_contents instead.

For example:

$skin = file_get_contents('/absolute/path/to/skin.png');

// or

$skin = file_get_contents('../../relative/path/to/skin.png');
balex25 commented 6 years ago

@jamiebicknell thank you! Works with file_get_contents.

Also, it is hard to implement support for capes? Like as: https://i.imgur.com/zj9Fjmt.png (I think it's also support for skin overlay).

Naxdy commented 6 years ago

@jamiebicknell I've just read the skin API page over at http://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape again, and it states that:

This has a much stricter rate limit: You can request the same profile once per minute, however you can send as many unique requests as you like.

Which suggests that the 600 API calls per 10 minute limit may not apply. Have you tested this?

advocaite commented 4 years ago

created a pull request