Open jazzy348 opened 3 years ago
Same here mate, same here.
There is very thorough documentation regarding the OAuth flow if authenticating a user on your own website, but almost nothing exists if you simply want to get a list of patrons using your own access token - and the information that does exist is contradictory and doesn't seem to match the current version and features of the API.
If I find more information I'll update here.
@jazzy348 - I got it working, but had to force composer to use the old version:
"patreon/patreon": "^0.3.1",
Once I did that and ran a composer update patreon/patreon
, I was able to use the abundance of examples found online because they actually map up with the function calls available in that older version of the library.
I'm not sure what's going on with version 1.0.0, it seems completely broken and has confused many people that I found across Stack Overflow and several different forums.
Code (only works for 0.3.1 and not 1.0.0 -- working as of 23 April 2021):
// Connect to the API using access token
$patreon_api = new \Patreon\API($access_token);
// Get the campaign ID as it's required for the next step
$campaign_response = $patreon_api->fetch_campaign();
$campaign_id = $campaign_response->get('data.0.id');
// Get a list of pledges for the campaign ID
$pledges_response = $patreon_api->fetch_page_of_pledges($campaign_id, 50);
foreach ($pledges_response->get('data')->getKeys() as $pledge_data_key) {
$pledge_data = $pledges_response->get('data')->get($pledge_data_key);
$pledge_amount = $pledge_data->attribute('amount_cents');
$pledge_currency = $pledge_data->attribute('currency');
$patron = $pledge_data->relationship('patron')->resolve($pledges_response);
$patron_full_name = $patron->attribute('full_name');
echo "{$patron_full_name} is pledging {$pledge_amount} cents {$pledge_currency}" . PHP_EOL;
}
Hopefully that is enough to get you or anyone else started.
The $access_token
is an API v2 token.
Register one here if you don't have it yet: https://www.patreon.com/portal/registration/register-clients
I'm lost and confused, please help.