Thanks for the feedback, Zanaras
Below code is more in detail. Using bogus codes/tokens/urls not original ones
My button page code. This is where the user can click on to “Link their Patreon account” :
<form action='https://www.patreon.com/oauth2/authorize' method='GET' enctype='application/x-www-form-urlencoded'>
<input type='hidden' name='response_type' value='code'/>
<input type='hidden' name='client_id' value='QPOEVaQOWE-PNVQEqVQPRVfBQRPQzVWERQPhWjORVQPWRkVQP_iORVMVPPEU_QTV'/>
<input type='hidden' name='redirect_uri' value='https://mywebsite.com/buttonpage.php'/>
<input type='hidden' name='state' value='$useremail'/>
<tr>
<th><b>Link your Patreon account</b></th>
<td>
<input type='submit' name='PButton' value='Link' class='SButton'/>
</td>
</tr>
</form>
If the user clicks on the above button, they are taken to a Patreon page, where they can confirm/deny. Let’s assume they click on confirm. As per the redirect specified both on the Patreon Client API and the Form, it sends the user back to the website above, which receives a GET request:
<?php
include('path/API.php');
include('path/OAuth.php');
use Patreon\API;
use Patreon\OAuth;
if ($_GET['code'])
{
$the_code_raw = $_GET['code'];
$the_client_id="QPOEVaQOWE-PNVQEqVQPRVfBQRPQzVWERQPhWjORVQPWRkVQP_iORVMVPPEU_QTV";
$the_client_secret="YWz4PELwGMEtOEFPy5WMBZ-3EQ_j8a7OWPlL2GnjM6VNc1B_z0WOW9UEn4413YRH";
$the_re_url = "https://mywebsite.com/buttonpage.php";
$oauth_client = new OAuth($the_client_id, $the_client_secret);
$tokens = $oauth_client->get_tokens($the_code_raw, $the_re_url);
$access_token = $tokens['access_token'];
$refresh_token = $tokens['refresh_token'];
}
?>
The above will provide the access token and the refresh token. In the next code, I attempt to access or retrieve user info, with new API using the access token obtained above. Imho, it should last 30-31 days therefore using it should yield a result:
<?php
include('path/API.php');
include('path/OAuth.php');
use Patreon\API;
use Patreon\OAuth;
$api_client = new API("P7QLF2OWMJ-VNEBDSOIF14MKEO6ER2KJEO0GO8QQLSP"); //access token
$patron_response = $api_client->fetch_user();
var_dump($patron_response);
?>
The API Result should by default return an array. At least, that’s what it described in the documentation.
Curl is enabled and on 7.66
I am using the user access token and not the creator access token.