[PHP] fetch_user() returns HTTP 403 when logging in with other account

Hello,

I’m trying to make a patreon pledge verification system for my game. I’m currently at the stage of obtaining the user information using fetch_user(). This all works fine if I log in with my creator account. But when I log in with a patron account, the API call returns the following:

403 You do not have permission to view OAuth Client with id <client ID, correct>. 

Everything before this step, including the OAuth token obtainment seems to run correctly, so I’m a bit at a loss. I do need to point out I am new at web development and PHP, but have quite some experience making video games.

Here’s the code I’m using so far:

<?php
  require_once __DIR__.'/vendor/autoload.php';

  use Patreon\API;
  use Patreon\OAuth;

  include 'vars.php'; // Client ID/Secret, redirect URL.

  if ($_GET['code'] != '')
  {
  	$oauth_client = new OAuth($client_id, $client_secret);

  	$tokens = $oauth_client->get_tokens($_GET['code'], $redirect_uri);
  	$access_token = $tokens['access_token'];
  	$refresh_token = $tokens['refresh_token'];

    echo nl2br("Access token: $access_token \n Refresh token: $refresh_token \n");

    $api_client = new API($access_token);
    $user_info = $api_client->fetch_user();

    if ($user_info->has('errors'))
    {
      $error = $user_info->get('errors')->get(0);
      $error_a = $error->get('id');
      $error_b = $error->get('status');
      $error_c = $error->get('code');
      $error_d = $error->get('title');
      $error_e = $error->get('detail');
      echo nl2br("$error_a \n $error_b \n $error_c \n $error_d \n $error_e \n");
    }
    else
    {
      $user_data = $user_info->get('data');
      $user_id = $user_data->get('id');
      echo "$user_id";

      $user_pledges = $user_data->relationship('pledges');
      //var_dump($user_pledges->getKeys());
    }
  }
  else
  {
    echo "Error: User denied authorization";
  }
?>

I’m using what seems to be version 0.3.1 of the patreon php libraries.

Can you try version 1.0.0 that’s ready to use with API v2 and see if it will just work. You would have to use v2 credentials, of course.

Ah yes, I soon found out after posting that 0.3.1 was outdated, yet installed by default by Composer. Fixed it by uninstalling and installing using: composer require patreon/patreon:dev-master

1 Like