At the frontend I get an respone after authorization:
code: tu6iaRFSFUTpsxq1DeosyTlso8JUxl (token)
state: None
frontend:
const test = async () => {
( url, method,body, headers)
await request('/patreonApi/protected', 'POST', {token: tu6iaRFSFUTpsxq1DeosyTlso8JUxl}, {
ContentType: "application/x-www-form-urlencoded"
}).then(res => {
console.log(res)
})
};
backend:
const patreonApi = require('patreon');
const patreon = patreonApi.patreon;
router.post('/getUserInfo', (req, res) => {
const {token} = req.body;
console.log(token) // string - tu6iaRFSFUTpsxq1DeosyTlso8JUxl
const apiClient = patreon(token);
return apiClient('/current_user/campaigns')
.then(({store}) => {
const _user = store.find('user', id)
const campaign = _user.campaign ? _user.campaign.serialize().data : null
const page = oauthExampleTpl({
name: _user.first_name,
campaigns: [campaign]
})
return res.send(page)
}).catch((err) => {
const {status, statusText} = err
console.log('Failed to retrieve campaign info')
console.log(err)
return res.json({status, statusText})
})
});`
Response - Failed to retrieve campaign info
error: Body {
url: ‘https://www.patreon.com/api/oauth2/api/current_user/campaigns’,
status: 401,
statusText: ‘UNAUTHORIZED’,
…
}
I tried passing Creator’s Access Token. Everything works perfectly. But with a user token, I get an error.