Logged in user's pledge level

Hello,

I’m using django-allauth to authenticate users (uses API v1), which adds a json to the database with the following info:

{"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”: “24461189”, “type”: “pledge”}]}} would have the ID of the current tier, but after testing with a second account it seems to differ each time.

How could I check if a user has a specific pledge/tier level on my campaign to display additional content?

Thank you!

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 (python):

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.

1 Like