Composer required?

I’ve been out of php development for some time now and just wanted to build a simple “Login with Patreon”-PHP Script that checks the pledge level of the user on my website.

However, I don’t have my own web server anymore and am just using the typical webspace solutions where you don’t get access to the php.ini. So I looked into the Patreon API for PHP, which seemed simple enough. However, upon my first try, I realized that my PHP script stopped working as soon as I tried to even import the patreon api. Even worse for me, my webhosting service seems to have disabled all php warnings and errors, which is an absolute horror.

So I saw that there’s a typical “require composer” code in the first line of the patreon.php script.
However, I’m not able to install composer fully as it needs me to set the environment variables.
Do I really need to get a web server in order to get something as simple as an OAuth for Patreon working? It’s the same thing for javascript as well…

Seems a bit much for a company that is trying to help artists and not companies.

That’s only if you want to download the scripts using composer.

What version of PHP is your server using? You can also throw this at the top of your PHP testing page to enable error reporting on that page:

ini_set('display_errors', 1);

I’m on PHP 5.3.29. Thanks for the error reporting command. I completely forgot about that.

The problem I’m having is that either the script doesn’t find the autoload.php (which would come from composer.)
or… if I comment that require out, I get:

Parse error: syntax error, unexpected ‘[’, expecting ‘)’ in /hp/ck/ac/fz/www/relattic/lib/Patreon/API.php on line 14

So I don’t see how to use the plugin without composer, which I can’t install.
I’m guessing that there are still scripts missing. What other ways to load these scripts are there?

Hm, seems like the github was updated 6 days ago with some new libraries.
You can try the old ones, here:

1 Like

okay great. thanks.

I’m using the old code now, including the old example oauth code, but I get the following error:

Notice: Undefined index: access_token in /hp/ck/ac/fz/www/relattic/patreon.php on line 57

Notice: Undefined index: data in /hp/ck/ac/fz/www/relattic/patreon.php on line 61

Notice: Undefined index: included in /hp/ck/ac/fz/www/relattic/patreon.php on line 62

Here’s the code:

$client_id = "xxxxx";      // Replace with your data
$client_secret = "yyyyyyy";  // Replace with your data
$creator_id = "zzzzz";     // Replace with your data

$oauth_client = new Patreon\OAuth($client_id, $client_secret);
$tokens = $oauth_client->get_tokens($_GET['code'], "http://localhost:5000/oauth/redirect");
$access_token = $tokens['access_token'];

$api_client = new Patreon\API($access_token);
$user_response = $api_client->fetch_user();
$user = $user_response['data'];
$included = $user_response['included'];
$pledge = null;
$campaign = null;
if ($included != null) {
  foreach ($included as $obj) {
    if ($obj["type"] == "pledge" && $obj["relationships"]["creator"]["data"]["id"] == $creator_id) {
      $pledge = $obj;
  foreach ($included as $obj) {
    if ($obj["type"] == "campaign" && $obj["relationships"]["creator"]["data"]["id"] == $creator_id) {
      $campaign = $obj;

echo $user['full_name'];
echo ": ";
echo $pledge['pledge_cap_cents'];

Could it be related to the fact that I can’t be a patreon of my own profile and so he doesn’t recognize my profile as valid?

I think the issue you have is your redirect URL. It needs to be the same one you setup in your client on Patreon’s site, and it needs to be the public url.

1 Like

ah i see… there was one more line… didn’t see that I had to fill it in there.

but it still doesn’t change anything. same error. The code is appended in the url and everything.

maybe the $creator_id isn’t correct? I haven’t found what to input so I tried both the Creator’s Access Token and the username.

@glaap hmm for creator id one thing to try is this under “installation instructions” I believe it’s the right ID. We just put that up a few days ago, and realize we should totally surface that better elsewhere!

Let me know if that helps. I think it’s what you need.

EDIT: Also I have verified that creator id and user id are the same. I apologize for the confusing nomenclature - we’ll clean that up as well.

hmm… it’s a bit confusing. it sounds like the client id is the same thing as the creator id in that text.

however, I found my creator id (which is a numerical value) now purely by experimenting with an extra account and experimenting with the oauth response. I haven’t seen that number anywhere on patreon before so right now I think it’s just not there honestly.

that said… it works now, but the creator id should be visible somewhere in the profile

1 Like

Good to hear! Another way to confirm it is to ‘view source’ of any patreon page and search for creator_id

45 AM

I agree, this is too confusing for something so essential.

Ah that would have been nice to know.
Anyways, everything works perfectly now.

One more thing to remember though is that I had to use the old api build 0.1.0 instead of the new 0.2.0 because I can’t install composer on a regular webhosting.

1 Like

Good to know that. I’m going to ask internally for advice on what needs to happen there.

EDIT Also thanks to @LordHarvie for all the fast help here

1 Like

I just finished a first version of a OAuth2 client driver for league.

As to composer and your php version. Your php version isn’t supported anymore, php 5.6 is close to being abandoned, you should seriously considering moving to 7+. Composer helps you with dependencies, it’s a great tool and improves your application as well by allowing PSR2/4 autoloading to be integrated into your application.

Of course it’s a good tool and all, but the fact that it’s required is just not realistic.
Most webhosters that you can rent don’t let you install anything and only have PHP5. I can’t update that nor can I install composer. I also can’t install node and such.

It’s just impossible for 90% of people, that are not primarily web developers, so a simple PHP solution should really be supported. Luckily Version 0.1 provides exactly what I need and it works perfectly.

I have my own wrapper for the API that I wrote that I’ve been considering polishing up and releasing here for anyone that needs it. It basically does what the new PHP solution does, just without the dependencies.

Hey glaap! composer isn’t doing anything magic in the OSS repo, it’s just linking to this one library:

There are two options (strongly recommend #1):

  1. You can download and install composer locally, run php composer.phar install locally, then upload the folder after it’s done downloading the dependency. Composer is just plain PHP, if your server can run the Patreon PHP script, you can run the library once Composer has downloaded it for you.
  2. You can just download that library, same as you’ve downloaded the Patreon library, and put it inside the Patreon folder (likely under a subfolder, like vendor/). Then, you can link to that dependency manually, same as if it was first-party.

We moved to an official JSON:API parser because, if you look at the majority of GitHub issues, people were having difficulties understanding how to parse and understand JSON:API. The new version also does not need to know your creator_id, which was what was tripping you up about the old version. :+1:

1 Like

I feel like the problems you’re talking about here are not because the plugin was bad, but because there’s absolutely NO documentation. And that’s still the same now. There’s no mentioning on how to get this to work on a server anywhere. The whole composer thing is a mess that no normal person will go through with if they can’t even understand how to use the plugin.

Anyways, my plugin has stopped working as of yesterday. Did you change something to not support the old API altogether anymore? I can’t get the access token anymore:

$oauth_client->get_tokens($_GET[‘code’], “##myurl##”);

only returns 0 which worked perfectly just a week ago. ($_GET[‘code’] does contain the return code!)

I wanted to push out a new update to my patrons today, but I can’t now because the API is not responding anymore.

Is it still not working? I use the old API and just tested it to make sure things were still working.
Is the code parameter not being set in the redirect URL after authorizing on Patreon?

code parameter is set, but tokens is still 0