patreon / patreon-python Goto Github PK
View Code? Open in Web Editor NEWInteract with the Patreon API via OAuth
License: Apache License 2.0
Interact with the Patreon API via OAuth
License: Apache License 2.0
I've found a number of users who, according to the Patreon Manager, have their Status set to 'Declined' but when using this API to query the database the pledge attribute 'declined_since' for these users is None.
This is making it hard for me to guarantee that my backend database is consistent with what Patrons are actually active (according to the Patreon Manager).
I want to use the API to fetch data from creators I support on Patreon with my own account. I created a client and found my creator access token.
import patreon,json
client_id = " " # My client ID
client_secret = " " # My client secret
oauth_client = patreon.OAuth(client_id, client_secret)
tokens = {}
with open('patreontokens', 'r') as tfile: # Creator access and refresh tokens stored in a file
tokens = json.loads(tfile.read())
tokens = oauth_client.refresh_token(tokens["refresh_token"]) # Refresh the tokens
with open('patreontokens', 'w') as tfile:
tfile.write(json.dumps(tokens))
creator_access_token=tokens["access_token"]
api_client = patreon.API(access_token)
ident = api_client.get_identity()
print(ident)
I read about a similar issue here which is why I am refreshing the token.
The output of the program is:
{'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 credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.", 'id': 'ca7835a3-90f2-4d1e-aa99-188a9efc5285', 'status': '401', 'title': 'Unauthorized'}]}
I have confirmed by doing print(token) that the refreshed token matches the one given to me at https://www.patreon.com/portal/registration/register-clients
The documentation recommends using &state
for CSRF in step 1, but the example code doesn't appear to use it. Is this a security problem?
Does not import properly when tested in Python 2.7.8, failing on this:
from datetime import timezone
There is no "timezone" object to import from the "datetime" module. There is one in the "time" module -- perhaps this is what was intended? I have not yet found out whether this is really the same object, but so far, the module works with this line altered to:
from time import timezone
Hi, I'm having trouble to get the optional fields from the pledges. I need to get status
see https://docs.patreon.com/#pledge
"type": "pledge"
"id": <string>
"attributes": {
"amount_cents": <int> // Amount cents in the currency used by the patron
"created_at": <date>
"currency": <string> // Currency code of the pledge event (USD, GBP, EUR etc.)
"declined_since": <date>
"patron_pays_fees": <bool>
"pledge_cap_cents": <int>
// optional properties
"total_historical_amount_cents": <int>
"is_paused": <bool>
"status": <string> // The status of this pledge (valid, declined, pending, disabled)
"has_shipping_address": <bool>
}
"relationships": {
"patron": ...<user>...
"reward": ...<reward>... // Tier associated with this pledge
"creator": ...<user>...
"address": ...<address>...
}
}
Is this supported in the python api? what I am supposed to pass into the function fetch_page_of_pledges
to retrieve the status
? It seems to expect a dictionary? I tried many things but I cannot seem to get the pledge status
Would you please help and clarify what I should pass to the function below to get the pledge status?
pledges_response = api_client.fetch_page_of_pledges(campaign.id(), 25, cursor=cursor,fields='status'})
Because version 0.5.1 is not published on pypl.org I had to install the current version by using the following command pip install git+https://github.com/Patreon/patreon-python
However, despite the installation being in the correct directory and the schemas directory being in there, I cannot import anything from the schemas directory.
This is a problem because the contents of that module are needed in order specify the information you'd like patreon to return.
Hi. I'm trying to run the example page to understand better how this api works, and I'm not having success.
I'm getting KeyError: 'refresh_token' error, and I don't know why. My patreon_creator_refresh_token is right.
LOG: https://pastebin.com/KaZV0PXU
Config file: https://pastebin.com/NgTTNf4G
Will this package be properly updated? It is nearly 2023.
Also the documentation for iterating over the pledged users in the readme is incredibly out of date even with the current version of the library.
def PComplete(request): #catch the return from the patreon oauth site, sanitize data, pass data to demplate, redirect back to home page, somehow cache the data??
print(request.GET.get('code'))
oauth_client = patreon.OAuth(client_id, client_secret)
access_token = request.GET.get('code')
api_client = patreon.API(access_token)
user_response = api_client.get_identity()
user = user_response.data()
print(user)
memberships = user.relationship('memberships')
membership = memberships[0] if memberships and len(memberships) > 0 else None
return render(request, 'dashboard.html', {'p_user' : user, 'p_member' : membership})
Here is my views request, everything works prefectly up until the point where apiclient.get_identity() is called, this occurs.
AttributeError at /accounts/patreon/login/callback/
'API' object has no attribute 'get_identity'
Patreon and its requirements (requests, six) are installed via pip3 all in a virtual env with the project
Maybe I am doing something wrong, Any help would be appreciated.
I'm trying to use patreon api with python.
patreon-python is a great library but v0.5.1, which use latest api endpoints, is not available on pypi.org.
Do you plan to publish this version on pypi?
Python 2 is no longer maintained and is considered very insecure/bad to be used in new systems.
By supporting it, you're advocating to mostly non technical people that they should be using noncompliant systems that put their systems and members at risk, and asking the technical people who know better to suffer attempting to do so.
It's best for Patreon and the people that support it, as well as their members, that this only support a modern python 3 release as everything python related that is still supported has already migrated to python3 fully.
This would also simplify the setup and stop people from having as many installation issues, in turn lowing costs for patreon to support it.
Hey there,
Just playing around with the module and the examples in the readme (examples folder appears to be empty?) references flask for signing in.
I have literally 0 experience with flask, and therefore got an error even trying the sign in a user bit. Is flask *required( if not, what sort of things is it looking for here? It mentions code is a required argument. but what code?
Thanks
Using: https://docs.patreon.com/?python#paging-through-a-list-of-pledges
import patreon
access_token = '...' # 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
Error:
Traceback (most recent call last):
File ".\start.py", line 45, in <module>
main()
File ".\start.py", line 28, in main
get_all_data(ACCESS_TOKEN)
File "patreonapi.py", line 117, in get_all_data
get_pledge_data(api_client, campaign.patreon_id)
File "patreonapi.py", line 90, in get_pledge_data
cursor = api_client.extract_cursor(pledges_response)
File "C:\Python27\lib\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/<removed>/pledges?page%5Bcount%5D=10&sort=created&page%5Bcursor%5D=2017-12-03T18%3A06%3A42.344287%2B00%3A00')
Related to #19, which was apparently solved in #20, reverted in #21 and a next mention of six
in #22 .
Environment:
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
PS C:\Users\Seb> [Environment]::OSVersion
Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 10.0.17134.0 Microsoft Windows NT 10.0.17134.0
Workaround as described in #19 still works:
Replace:
cursor = api_client.extract_cursor(pledges_response)
With:
from urlparse import urlparse, parse_qs
# Temporary workaround until Patreon fixes the issue.
next_link = pledges_response.json_data.get('links', {}).get('next')
if not next_link:
break
query = urlparse(next_link).query
parsed_qs = parse_qs(query)
cursor = parsed_qs['page[cursor]'][0]
I don't really know how to use the API with Discord.py, but I want it so there is like a patreon-discord thingy. It could be in discord.py or discord.js etc.
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...')
What's the best way to do this? Deploying new API schema on patreon.com kicks off a script which opens a PR against this (and the other open source) repo(s)?
I see in example you call to patreon.API.get_identity()
But when i exactly try the same I get:
AttributeError: 'API' object has no attribute 'get_identity'
Has it been removed?
How do I get currently_entitled_amount_cents?
If the payment has been completed and the payment has expired (cancelled) despite the remaining expiration date, users cannot be imported through fetch_page_of_pledges
.
How can I get it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.