I’m using django-allauth to authenticate users (uses Patreon's API v1), which adds a json to the database with the info below. I would like to show extra content on the site if the user's pledge matches a particular tier (or is above one).
{
"attributes": {
"about": null,
"can_see_nsfw": true,
"created": "2019-05-20T20:29:02.000+00:00",
"default_country_code": null,
"discord_id": null,
"email": "admin@email.com",
"facebook": null,
"facebook_id": null,
"first_name": "Adm",
"full_name": "Adm Nsm",
"gender": 0,
"has_password": true,
"image_url": "https://c8.patreon.com/2/200/21383296",
"is_deleted": false,
"is_email_verified": false,
"is_nuked": false,
"is_suspended": false,
"last_name": "Nsm",
"social_connections": {
"deviantart": null,
"discord": null,
"facebook": null,
"instagram": null,
"reddit": null,
"spotify": null,
"twitch": null,
"twitter": null,
"youtube": null
},
"thumb_url": "https://c8.patreon.com/2/200/21383296",
"twitch": null,
"twitter": null,
"url": "https://www.patreon.com/user?u=21383296",
"vanity": null,
"youtube": null
},
"id": "21383296",
"relationships": {
"pledges": {
"data": [
{
"id": "24461189",
"type": "pledge"
}
]
}
},
"type": "user"
}
At first I though relationships.pledges.data.id would have the ID of the current tier and with that I managed to add an extra block of content for a specific user, but apparently that was only wishful thinking; after testing with a second account the ID that I though was the pledge level seems to differ each time. I imagine I might need to request more info from Patreon's API, but am unsure how to get what I need back.
EDIT:
From what I can gather, I would need to request the currently_entitled_tiers from /api/oauth2/v2/members/{id}
The problem is that the ID required there is not the same ID I get after a user logs in. So I would first need to use the oauth access token that's been generated and GET /api/oauth2/v2/identity for the long ID number.
My current problem is that when I try to get the ID from /api/oauth2/v2/identity I receive a 401 error code:
<Response [401]>
{'errors': [{'code': 1, 'code_name': 'Unauthorized', 'detail': "The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentia
ls (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.", 'id': 'b298d8b1-73db-46ab-b3f4-545e6f934599', 'status': '401', 'title': 'Unauthori
zed'}]}
What I'm sending is:
headers = {"authorization": "Bearer " + str(access_token)} # User's Access Token
req = requests.get("https://patreon.com/api/oauth2/v2/identity?include=memberships", headers=headers)
If I get the proper ID through /api/oauth2/v2/campaigns/{campaign_id}/members I can request from /api/oauth2/v2/members/{id} and get what I need, but that middle step using the currently logged in user to get their ID eludes me.
Thank you.