Patreon / patreon-js

Use the Patreon API via OAuth.
MIT License
151 stars 30 forks source link

Need more help applying what is written in guide #9

Open MehmetKursat opened 7 years ago

MehmetKursat commented 7 years ago

How do I use this pledge_schema thing to achieve this:

For instance, if you wanted to request the total amount a patron has ever paid to your campaign, which is not included by default, you could do:

const patreonAPIClient = patreonAPI(access_token)
const url = jsonApiURL(`/current_user`, {
  fields: {
    pledge: [...pledge_schema.default_attributes, pledge_schema.attributes.total_historical_amount_cents]
  }
})
patreonAPIClient(url, callback)

I required jsonApiURL from here https://github.com/Patreon/patreon-js/blob/master/src/jsonapi-url.js but then what? I get Uncaught error: pledge_schema is not defined

21echoes commented 7 years ago

Hey @FiatPax ! Try import pledge_schema from 'src/schemas/pledge'

MehmetKursat commented 7 years ago

Alright I tried and now I get this error: Cannot read property 'Symbol(Symbol.iterator)' of undefined

Just in case you need to see my code

var patreonAPI = patreon.default
var patreonOAuth = patreon.oauth

test(request, reply) {
        var patreonAPIClient = patreonAPI(access_tkn)

        const url = jsonApiURL(`/current_user`, {
            fields: {
                pledge: [...pledge_schema.default_attributes, pledge_schema.attributes.total_historical_amount_cents]
            }
        })
        patreonAPIClient(url, function (err, res) {
            reply(res)
        })
    }
anton-minnion commented 6 years ago

Struggled with trying to inlude the total_historical_amount_cents field in the json return. Found the schemas in the 'dist' folder of the npm install:

import pledge_schema from 'patreon/dist/schemas/pledge';

But not working, just get a 500 error following the docs.