401 Unauthorized and long API calls

Been having this issue on and off and I’m all out of ideas what to do. This error slows down my website by more than a second. It’s a lot when by default, with plugin deleted, it loads in 500-700ms. The only thing I use it for at the moment is removing ads for logged in Patrons. Here’s Query Monitor logs:

Here’s how the health check looks like (there’s a lot more, but would be too long):

These are the last 50 connection issues encountered by your site when contacting Patreon API. These are here for general info on health of the connection of your WP site to Patreon API. They only constitute an error if there are a lot of recent ones. Healthiest integrations should have a number of them (up to 50) in the long run.

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID cee9b8c0-bcc2-5db0-97c9-f5e96554b2f8 - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"cee9b8c0-bcc2-5db0-97c9-f5e96554b2f8","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID e44d043c-d969-52ca-8878-4dc3ddccf86b - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"e44d043c-d969-52ca-8878-4dc3ddccf86b","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID 325a233d-192a-52f6-9224-099c74bd05f8 - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"325a233d-192a-52f6-9224-099c74bd05f8","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID 3a7c2a83-fdc4-54ef-a3bc-89b1bd69dfeb - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"3a7c2a83-fdc4-54ef-a3bc-89b1bd69dfeb","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID 21365ed0-8809-5e5a-86d2-aed43486e87c - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"21365ed0-8809-5e5a-86d2-aed43486e87c","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

**0 days ago**

fetch_user - API v2 Class - UUID b7f6c12e-0900-5e9e-9e02-75fc101a2d99 - Response code: 401 Response :{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"b7f6c12e-0900-5e9e-9e02-75fc101a2d99","status":"401","title":"Unauthorized"}]}

**0 days ago**

Response code: 401 Response :{"error": "invalid_grant"}

The strange thing is, this error is happening on my production website, while on my development website it’s calling this API 200 OK on each page load. This plugin been giving me the most trouble and performance issues in many years of working on WordPress.

I tried:

Also tried deactivating and deleting plugin, making sure plugin folder is deleted, and reinstalling, doing all the above again.

Tried to disable all plugins except Patreon and my own essential plugins that do not modify requests in any way, basically matching the plugin stack with my development website.

Tried deleting plugin, deleting all options starting with “patreon” from wp_options database table, deleting all rewrite rules that had anything to do with Patreon from rewrite_rules in wp_options and reinstalling plugin.

Environment:

WP 5.9.1 with PHP 8.0.15
Patreon WordPress 1.8.2 with API v2

Does this happen with PHP 7.X?

Yes, but it now occasionally breaks my website as I started using features of PHP 8, but the exact same 401 error comes up.

I think I’m onto something. At least I’m reassured that the functionality of the plugin actually works and it does gate content for at least not-logged-in users (don’t know if it actually can retrieve exact pledge user has for content gated for specific tiers).

What I found out is that those API calls, that I showed on the initial screenshot, are never made when logged out, and there’s no errors when trying to access gated content (Patreon_Frontend::gate_custom_content() method). Tested through Query Monitor with authentication cookie. But now why is it giving the 401 error when logged in on my production website, when it seems to be working fine with a 200 OK response on my development website? What could cause this anyway?

Here’s how it looks like when logged in on my development website:

Can you find the IP that your host/server is using for production website and DM it to me via the forum?