You should not be doing this in the first place. Not only is this inappropriate to a player’s privacy, but also they may identify differently than the API suggests.
You are not allowed to make web calls from the client, so you can’t use this API in the first place.
Prompt the user in game with a question on their gender, but also leave the freedom to not answer in the first place.
Furthermore, I believe a request like this would require authentication (e.g. access to the user’s account, whether it be in the form of a cookie or otherwise), thus rendering it impossible to use in your game.
Any information that might be sensitive or identifiable to a given person. This requires you to consider that can be sensitive though.
Things like age and location are very obvious ones that you should not ask the player, but subtle ones like gender can be asked, but its best if you either don’t in the first place or give the player ways to customize their settings differently, or to give them the option to not respond at all.
I don’t think you should try to do this since it would be described as personal information. You can do what @DrKittyWaffles said and put in an option to select.
It’s not really wise to rely on avatar information to determine gender. For example I have a dragon avatar on – but how will that tell you I identify as male? What about users with no gender data (you can opt out of the male and female genders in your settings and upon signup now)?