<?php
use Patreon\API;
use Patreon\OAuth;
class PatreonWebClient {
private $client_secret;
private $client_id;
public $redirect_uri;
private $creatorAccessToken ="88G6b_1f3bmvYFSL4GQwMt-6VZ1xf-r2PDUgcct1dyo";
function __construct($botId)
{
$this->redirect_uri = "http://redirect.bayadic.com?botid=$botId";
$this->client_id = "mKjgbe9psJskSSaCBV9iNu2Krciaf7-cOhiJ0J8bJ_9NyCeLy81eHlgv0Ab42fkq";
}
function createLoginLink(){
$href = 'https://www.patreon.com/oauth2/authorize?response_type=code&client_id=' . $this->client_id . '&redirect_uri=' . urlencode($this->redirect_uri);
return $href;
}
function retriveTokens($code){
$oauth_client = new OAuth($this->client_id, $this->client_secret);
return $oauth_client->get_tokens($code, $this->redirect_uri);
}
function retriveUserDetailsByToken($access_token)
{
$api_client = new API($access_token);
$patron_response = $api_client->fetch_user();
return $patron_response;
}
function retriveCampaignMembers()
{
$api_client = new API($this->creatorAccessToken);
// You dont need the below line if you are going to use the return as array.
// $api_client->api_return_format = 'object';
// Now get the current user:
$campaigns = $api_client->fetch_campaigns();
$members = $api_client->fetch_page_of_members_from_campaign($campaigns['data'][0]['id'], 100);
return $members['data'];
}
}