I'm trying to implement the Patreon API on a project and I've hit a roadblock. I'm able to sign in and receive an authorization code after being redirected back to my site, but for some reason the array that is supposed to have the access and refresh tokens in them is null.
Im using the patreon package via composer https://packagist.org/packages/patreon/patreon
So the top of my code seems to be working fine. However, in case I'm completely blind and it is the issue I'm including it.
$client_id = 'xxxxxxxxxx'; // Replace with your data
$client_secret = 'xxxxxxxxx'; // Replace with your data
$redirect_uri = "http://localhost/Final%20API/thankyou.php";
// Generate the oAuth url
$href = 'https://www.patreon.com/oauth2/authorize?response_type=code&client_id=' . $client_id . '&redirect_uri=' . urlencode($redirect_uri);
$state = array();
$state['final_page'] = 'http://localhost/Final%20API/';
$state_parameters = '&state=' . urlencode( base64_encode( json_encode( $state ) ) );
// Append it to the url
$href .= $state_parameters;
$scope_parameters = '&scope=identity%20identity'.urlencode('[email]');
$href .= $scope_parameters;
echo '<a href="'.$href.'">Click here to login via Patreon</a>';
Notice: Trying to access array offset on value of type null in C:\MAMP\htdocs\patreon3.php on line 69
Notice: Trying to access array offset on value of type null in C:\MAMP\htdocs\patreon3.php on line 70
I get the code= returned so i'm trying to use it to get my tokens, but I'm coming up empty-handed and I don't know what I'm doing wrong here.
if ( $_GET['code'] != '' ) {
$code = $_GET['code'];
$oauth_client = new OAuth($client_id, $client_secret);
$tokens = $oauth_client->get_tokens($code, $redirect_uri);
$access_token = $tokens['access_token'];
$refresh_token = $tokens['refresh_token'];
Am I correct in thinking that the sticking point is that if statement? If so, what do I have to do to straighten it out?