HI there
I am trying to use the API (in Python) to get a list of all the email addresses for each pledge on a campaign.
I have the following code which returns the User IDs of all pledges made on a campaign:
def get_emails():
emails = set()
pledge_endpoint = 'https://www.patreon.com/api/oauth2/api/campaigns/{}/pledges?include=patron.null'.format(campaign_id)
def get_emails_from_page(url):
request = urllib.request.Request(url)
request.add_header('Authorization', 'Bearer {}'.format(access_token))
result = urlopen(request).read().decode('utf-8')
resultJson = json.loads(result)
for i in range(len(resultJson['data'])):
if resultJson['data'][i]['attributes']['declined_since'] == None:
user_id = resultJson['data'][i]['relationships']['patron']['data']['id']
if resultJson['links'].get('next'):
next_page = resultJson['links']['next']
get_emails_from_page(next_page)
get_emails_from_page(pledge_endpoint)
return(list(emails))
How do I now use those User IDs in an API call to access their email address?
I tried the following code on this endpoint https://docs.patreon.com/#get-api-oauth2-v2-members-id but got a HTTP Error 401: UNAUTHORIZED error message:
member_endpoint = 'https://www.patreon.com/api/oauth2/v2/members/{}'.format(user_id)
member_request = urllib.request.Request(member_endpoint)
request.add_header('Authorization', 'Bearer {}'.format(access_token))
member_result = urlopen(member_request).read().decode('utf-8')
member_resultJson = json.loads(member_result)
I note from the docs that this end point " Requires the campaigns.members
scope." - but I don’t know what this means and so this may be where I’m going wrong.
TIA