Get lifetime support

Can someone give me a example of how to obtain patron lifetime support using the API calls? (java, if possible)

Thanks in advance

Hey @JulioNIB!

Nick here from the Patreon platform team.

The lifetime support for a patron is reflected in the totat_historical_amount_cents property for the pledge endpoint.You’ll want to include that in your call!

1 Like

but how i would use this in API calls? im trying the example from:
https://docs.patreon.com/#fetching-a-patron-39-s-profile-info to get the info from user and see if he is my patreon or not, only missing thing is determine how much he pledge to me.

also how i would use the REST web service that i created in my page? so far i only can successfully call the WS directly from patreon login redirect, if i try to call the WS from my page after patreon login redirect to it (that is in same domain) i obtain a invalid token.

if i call:

https://www.patreon.com/oauth2/authorize?response_type=code&client_id=d4ujSz-kLbfdKsSz75MSXXp5sTVHcuhCl9r6tK-mR1x_UB4w5rcwcX14HpefNLpE&redirect_uri=https://nibws-200816.appspot.com/rest/service/mymethods

it works, but if i call:

https://www.patreon.com/oauth2/authorize?response_type=code&client_id=d4ujSz-kLbfdKsSz75MSXXp5sTVHcuhCl9r6tK-mR1x_UB4w5rcwcX14HpefNLpE&redirect_uri=https://nibws-200816.appspot.com

and try to use javascript to call the WS i obtain NULL for the token in this line:

JSONObject tokens = oauthClient.getTokens(code, redirectURI);

The Pledge Resource has a total_historical_amount_cents value which includes the total amount a patron has paid (less refunds) so you can use that determine the lifetime support value. The total_historical_amount_cents value is optional, so you need to explicitly list it as a value to be included with your request – note that when you specify one field, you must specify all that you wish to be included – e.g:

curl -X GET https://api.patreon.com/oauth2/api/current_user?fields%5Bpledge%5D=total_historical_amount_cents -H 'Authorization: Bearer {patrons-access-token}'

That will return the following:

{
    "data": {
        "attributes": {
            "about": "",
            "created": "2013-06-02T04:08:00+00:00",
            [...]
            "vanity": "sam"
        },
        "id": "12345",
        "relationships": {
            "pledges": {
                "data": [
                    {
                        "id": "1234567",
                        "type": "pledge"
                    }
                ]
            }
        },
        "type": "user"
    },
    "included": [
        {
            "attributes": {
                "total_historical_amount_cents": 0
            },
            "id": "1234567",
            "relationships": {
                [...]
            },
            "type": "pledge"
        }
        [...]
    ],
    "links": {
        "self": "https://www.patreon.com/api/user/12345"
    }
}

Then from there you will have access to the total_historical_amount_cents value, however, as far as I can tell the Patreon Java library does not support optional attributes at the moment so you would need to modify the library to allow for you to retrieve those values.

That said I’m a little unclear on the problem you’re encountering, what does ws stand for – are you using websockets? That sounds like an implementation detail of your application rather than something that would be related to use of the Patreon API.

Perhaps an outline of the OAuth flow will help you better understand the approach to take. The OAuth flow is roughly:

  1. A user visits your login page
  2. You redirect the user to the Patreon login page
  3. The user is asked the user to confirm that they authorise your application
  4. Patreon redirects the user back to your redirect_uri with a code query parameter
  5. You maks a request to the Patreon API (in the background) exchanging the code for an access token and refresh token
  6. You store the access token associated with the user in some way, and use that to make subsequent requests to the API, you could store it in a database, the users session, localstorage, your applications memory etc.

Are you able to share a better example of how your application works, is the code on GitHub? Are you able to share it here?

1 Like

A quick follow up to say: if you have a goal you’re trying to achieve and you’re not bound to a specific language, perhaps you could outline the goal instead and guidance can be provided to achieve that rather than to try and fix the problems with your current implementation, e.g:

  • I need an application that runs on Google App Engine
  • The application must let patrons log in using OAuth
  • The application should display their total lifetime value
1 Like

ok, let me try the curl thing :slight_smile:

about the second question, i developed a JAVA app that is hosted in google app engine, i want call a login page where user will login with his Patreon account and then my app or page will check if is a patreon or not. Some info about his profile will be saved in a database, all this is working except the page itself, so far i only can make it work if i direct call the webservice (the ws i was talking about) instead of calling the page that would use the webservice. Sorry if my questions are too much stupid hehe, im a desktop dev, never kidded with web before.