I have a site whereby Patreon users can connect and in doing so get access to a load of password protected podcasts. The use a Patreon link to sign up which creates them Wordpress users on our site. Each night the site runs a cron job to check that the Patreon user is still subscribing and if not, removes their access.
Unfortunately this process only works for a month and then the user needs to use the sign up link again to get the connection working. It defaults them to ‘no access’.
I believe what is happening is their access token is expiring. However, I can’t get the refresh token to work. I have followed the details on the site and I am sending a POST request with
POST www.patreon.com/api/oauth2/token
?grant_type=refresh_token
&refresh_token=<the user‘s refresh_token>
&client_id=<your client id>
&client_secret=<your client secret>
But I keep just getting an 405 MethodNotAllowed error returned.
0 =>
array (
'errors' =>
array (
0 =>
array (
'code' => 1,
'code_name' => 'MethodNotAllowed',
'detail' => 'The method is not allowed for the requested URL.',
'id' => '4bee062e-1ecc-4143-91e9-175cda9bb85d',
'status' => '405',
'title' => 'Method Not Allowed',
),
),
),
)
The code from the site is below:
// Refresh the user if a refresh token is present.
$refresh_token = $user->get('patreon_refresh_token');
if($refresh_token) {
$tokens = $this->refresh_user($refresh_token);
update_user_meta($user_id, 'patreon_key', $tokens['access_token']);
update_user_meta($user_id, 'patreon_refresh_token', $tokens['refresh_token']);
$key = $tokens['access_token'];
}
public function refresh_user($refresh_token) {
$url = "https://www.patreon.com/api/oauth2/token?grant_type=refresh_token&refresh_token=$refresh_token&client_id=$this->client_id&client_secret=$this->client_secret";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return json_decode(curl_exec($ch), true);
}
Any help that could be provided would be appreciated.