Unauthorized error when using new PHP api

That is the error the Patreon API returns when the access token provided is invalid. There are 3 reasons you might experience this error in the example project:

  1. You have not correctly set your Creator Access Token in the .env file (key PATREON_ACCESS_TOKEN)
  2. You are not correctly setting the user’s access token when they log in (only applicable if you edited the example)
  3. You have logged into the example using the same account that owns the campaign for which you’ve provided the creator access token, from the README:

:warning: Do not log in to your Patreon PHP website with your creator account. You must create a new account for testing. If you log in with your creator account then your Creator’s Access Token will be reset and all requests will fail. When that happens you will need to repeat Step 4 (of Accepting Logins) again. via patreondevelopers.com.

The steps to remedy this are:

  1. Ensure that you have correctly set the creator’s access token in your .env
  2. Ensure that you are using a separate test account to log in to the example application – if not, repeat step 4 from the README
  3. Ensure that, if you’ve modified login.php or patrons.php that you’re correctly setting the accessToken from the Patreon API response

If that doesn’t help, please let me know and I can investigate further for you :slight_smile:


Editing to add: you can quickly verify if an Access Token is valid by opening your terminal and running the following command:

curl -X GET https://api.patreon.com/oauth2/api/current_user -H 'Authorization: Bearer access-token'

So to easily determine if your Creator Access Token is valid you can run that command with access-token replaced with the value of PATREON_ACCESS_TOKEN from the .env file, e.g:

curl -X GET https://api.patreon.com/oauth2/api/current_user -H 'Authorization: Bearer zVd2NMt33xi1GtIE_IdzFTyc888usMjwRSinvnWHYGh7'
1 Like