Patreon / patreon-python

Interact with the Patreon API via OAuth
Apache License 2.0
122 stars 33 forks source link

Error in extract_cursor() method #19

Closed hate5six closed 6 years ago

hate5six commented 6 years ago

I'm attempting to replicate the example here for retrieving all pledges to a campaign: https://docs.patreon.com/?python#fetch-a-creator-profile-and-campaign-info

import patreon

access_token = nil # your Creator Access Token
api_client = patreon.API(access_token)

# Get the campaign ID
campaign_response = api_client.fetch_campaign()
campaign_id = campaign_response.data()[0].id()

# Fetch all pledges
all_pledges = []
cursor = None
while True:
    pledges_response = api_client.fetch_page_of_pledges(campaign_id, 25, cursor=cursor)
    pledges += pledges_response.data()
    cursor = api_client.extract_cursor(pledges_response)
    if not cursor:
        break

However, I get the following error (I'm using a valud access_token):

Traceback (most recent call last): File "get_patrons.py", line 16, in cursor = api_client.extract_cursor(pledges_response) File "/home/hate5six/hate5six.com/h5senv2.7/lib/python2.7/site-packages/patreon/api.py", line 74, in extract_cursor 'Provided cursor path did not result in a link', current_dict Exception: ('Provided cursor path did not result in a link', u'https://www.patreon.com/api/oauth2/api/campaigns...')

hunganh0403 commented 6 years ago

I have same problem and got a work around solution, hope it'll help until they fix this:

from urlparse import urlparse, parse_qs
cursor = parse_qs(urlparse(pledges_response.json_data['links']['next']).query)['page[cursor]'][0]
hate5six commented 6 years ago

@hunganh0403 interesting. What is the pledges_response object in your example? I'm using the code from the demo so it's a JSONAPIParser object. It doesn't have a get method so pledges_response['links']['next'] fails.

EDIT: looks like the following does the trick for me:

parse_qs(urlparse(pledges_response.__dict__['json_data']['links']['next']).query)['page[cursor]'][0]

hunganh0403 commented 6 years ago

pledges_response.json_data will do. I've edited in my comment. pledges_response in old version is json itself, I've copied my code without update to new Patreon API new version.

phildini commented 6 years ago

Hey there! Thanks for writing in, we're going to look into this.

mubix commented 6 years ago

Same issue, any updates?

mubix commented 6 years ago

The code here also has a typo (and doesn't work) https://docs.patreon.com/?python#fetch-a-creator-profile-and-campaign-info

The all_pledges should be pledges or the other way around.

all_pledges = []
cursor = None
while True:
    pledges_response = api_client.fetch_page_of_pledges(campaign_id, 25, cursor=cursor)
    pledges += pledges_response.data()
    cursor = api_client.extract_cursor(pledges_response)
    if not cursor:
        break
phildini commented 6 years ago

Hey there. I'm really sorry we've been so delayed on getting this fixed; I'm hoping we'll have an answer for you all this week!

lynneatan commented 6 years ago

Hi everyone, I am closing this issue as this problem should now be fixed in the latest version.