Java - v5 - How to get the current community for a channel

Your API logic is correct but make sure twitchName is a Twitch channel ID (ex: 12826) and not the channel name. The comment seems to indicate you are trying to pass a channel name and v5 requires channels IDs.

/channels/:channel_id/community is an unauthenticated request so you don’t need to worry about scopes, just make sure you are passing a valid client ID (not OAuth token) in the header.