[SOLVED] Cannot use object of type Art4\JsonApiClient\Document

Hey I’m trying to get the user’s info so I can send it to a database for their account. I have an issue I cannot wrap my head fully around. This is my code.

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

use Patreon\API;
use Patreon\OAuth;

$client_id = 'TheClientId';
$client_secret = 'TheClientSecret';
$redirect_uri = "https://redirect.com";

$access_token = "Users access token";

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

$email = $current_member['data']['attributes']['email'];?>

With this I get the error “Uncaught Error: Cannot use object of type Art4\JsonApiClient\Document as array” on the email line. What is the correct way to format that line so I can get the email of the user?

If you are using the PHP lib version you got from composer, that is outdated. Please use the one at github.

The one at githup is updated for v2 api and only uses v2 api. And it has art4 lib removed. The examples there should be much more comfortable to adopt.

1 Like

Thank you for the information, I’ll switch over to github right away, I didn’t notice at the time that the packagist version was outdated. That’ll likely fix all my issues, thank you!

1 Like

Hmm, now I’m getting another issue with this line

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

It appears get_tokens is undefined. I haven’t been able to spot get_tokens in the source either, is that something I’ll have to personally define?

get_tokens is in OAuth.php. Did you include that class?

1 Like

Ah, somehow I had missed that before while looking. I found the source of the issue, it seems I likely had messed up my composer or Patreon install due to the shuffling around as composer doesn’t hook up correctly, but including the Patreon source files directly into the problem areas solves the issue so I’ll debug what happened on my end there.

Sorry about the confusion, I just confirmed that things are working out and things are working which is exciting! I absolutely love this! Thank you again for being so helpful with my silly problems and informing me that the composer one was out of date.

You can just rm -rf that subdir (if linux) and clone git repo into the same dir and that should do it… Currently this lib doesnt have any relation with composer.

Oh gotcha. It was my first time working with this sort of thing so I followed everything to a T out of worry, so the instructions on installation to go to Packagist tripped me up, but it was a good lesson to learn to just go directly to github if possible.

Edit: Changed the title back to what it was originally so anyone else who has the same issue as me can quickly locate it.

1 Like