401 - Access denied when getting token

I am using the Java Patreon API. When I try and get OAuth authentication I get the error:

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=401, URL=https://www.patreon.com/api/oauth2/token

I have checked many times and the clientid and clientsecret are the same as those provided by the api. the redirectURI is also the same.
I have also tried both API versions 1 and 2 I get the same error either way.
How can I stop getting 401 errors?

(the code has been copied straight from README.md on the github repo.
Code:

	public void test() {
		try {
			String clientId = "###";
			String clientSecret = "###";
			String redirectUri = "https:www.google.com";

			String code = "test";

			PatreonOAuth oauthClient = new PatreonOAuth(clientId, clientSecret, redirectUri);
			PatreonOAuth.TokensResponse tokens = oauthClient.getTokens(code);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Are you using api v2 client and creator tokens?

I am using this repo: GitHub - Patreon/patreon-java: Interact with the Patreon API via OAuth which was linked on the patreonAPI page. Ive tried both using version 1 and version 2 on the patreon website side when getting the keys, both produce the same error.

I noticed a slight difference between the api page and the github repo as the api page said to use version 0.1.1 and the github repository said to use 0.4.2. I selected version 0.4.2 in pom.xml as I was following the guide on github.

The api page I was referencing: API Reference (just in case there is some other one that is more up to date that I have missed)

That repo may not be up to date. Try making a call to that endpoint through curl (or any other command line util or any online util) and see if your call and tokens have any issues. If not, then the library in the repo may be the problem.

I’ve done some more testing (firstly starting with shell commands) and it turns out the repository works correctly from my testing,
But the readme.md file skipped the step of getting the user code for the token request. I cannot find where that is done within the API so I have just written a custom HTTPSRequest to do it. Everything after that point appears to work as expected

You can check api docs for that. Its actually standard oauth2.

https://docs.patreon.com/#oauth