this code is almost verbatim from the api docs:
var patreon = require(‘patreon’),
patreonAPI = patreon.patreon,
patreonOAuth = patreon.oauth;
var creatortoken = ‘XXXXXXXXXXXXXXXXXXXXXX’;const patreonAPIClient = patreonAPI(creatortoken)
patreonAPIClient(‘/current_user/campaigns’)
.then(({ store }) => {
const user = store.findAll(‘user’).map(user => user.serialize())
console.log(‘user is’, user)
const campaign = store.findAll(‘campaign’).map(campaign => campaign.serialize())
console.log(‘campaign is’, campaign);
console.log(campaign);
})
.catch(err => {
console.error(‘error!’, err);
console.log(err);
});
My creator token was copied from the client I registered, I copied the value under “Creator’s Access Token”, and put it in that string.
Every time I just get 401 unauthorized.
Using patreon-js.
I’ve been able to get the info using this code:
(after comfirming with OAuth)
patreonOAuthClient
.getTokens(req.query.code, 'https://'+res.locals.host+'/user/update-patreon')
.then(function(tokensResponse) {
console.log('token response',tokensResponse);
var patreonAPIClient = patreonAPI(tokensResponse.access_token);
return patreonAPIClient('/current_user/campaigns');
})
.then(function(result) {
console.log('success')
})
.catch(err => {
console.error('error!', err);
});
This works, though it doesn’t have any info on pledges (which i need), even if I add ?includes=pledges.
Also, if I try to do it with the creator token, I still get 401:
patreonAPI(creatortoken)('/current_user/campaigns')
.then(function(result) {
console.log('success')
})
.catch(err => {
console.error('error!', err);
});
I’ve also tried to refresh tokens, which according to the docs you just need to " make a POST request to the token endpoint with a grant type of refresh_token
".
var url = 'www.patreon.com/api/oauth2/token'+
'?grant_type=refresh_token'+
'&refresh_token='+siteData.patreon.refresh_token+
'&client_id='+process.env.PATREON_CLIENT_ID+
'&client_secret='+process.env.PATREON_CLIENT_SECRET;
request.post(url, {}, (error, response, body)=>{
if (err) return console.log('failed to refresh patreon token',error);
console.log(body);
});
but that gives a 401 error too.