I’m developing a static site and I want to pull in some extremely basic data. This is my first rodeo with API, aside from figuring out how to pull in Twitch API. I have been wrestling with the Patreon API for two months now, and I must be missing something critical that I can’t glean from the docs.
What I’m trying to do first before I do anything else is just figure out the URL I’m supposed to be calling. I want to get number of patrons and total amount pledged to start with, so I can display it on my website. Once I can do that, I’ll expand to something more complex.
- I will work on environment variables/security measures/etc etc after I get the basic stuff working and I know that I’m on the right track.
Since there will be no sign in on the website, unless I’m mistaken, there’s no reason to go through the OAuth process. I just use my access token from the client I received. I just want to pull in variables that have nothing to do with who is signed in.
From what I understand, I’d be calling…
(where ##### = campaign_id)
…but of course that’s unauthorized, because there’s no access token.
So, I suppose my questions are:
- Do I have to go through the OAuth process every time, even though no one is logging in? The API docs say you can use your access_token in place of OAuth when making API calls, but does not make it clear how to do so.
- Is there really no way to limit the scope of the client when you make it? If someone got a hold of my client ID & secret or access token, they could just pull any information whatsoever and there’s seriously no way to say “just look at the public stuff please”?
- Is it impossible to call the URL on a browser without going through the OAuth first, and therefore I have to do it in subsequent XMLHttpRequests?
- Is my problem maybe that my client, including the redirect URI, is currently using localhost? Will the redirect URI break things if I’m never using it, since no one is being redirected anywhere?
Let me know what I’m missing. I know I’m new to this, but I’m fairly competent as a coder and a learner, and my husband is more capable still, and we’re both stumped right now.
Thanks in advance!
1 - You dont need to go through oauth every time. Using a valid access token will allow you to make any call to the api on behalf of the patron. As long as you have requested the token for that scope.
You can just check the PHP lib for simple examples. WP plugin also has a working integration for doing oauth and gating functions.
2 - As far as i know creator token comes with all relevant scopes assigned. Your app client should only work with the scopes which were requested with a patron’s token so its limited to what scopes you request.
3 - If you use the patron’s access token you can make calls to api without oauthing.
4 - All urls need to be properly formed for login to work.When an access token expires it will need to be renewed by going through oauth. Something like a month duration.
At this point maybe it’s better if I don’t use the API at all, and just make a separate script to run and pull the information off my page. There is no gating. There is no integration. I literally just want to get my Patron Count and my Dollar Amount on my own site to display. Like hey, like my comic? Look at all these people already supporting me!
I personally loathe Wordpress and I am moving away from it; but even if I didn’t, I already stated that this is 1) a static site, and 2) a learning project for me.
So you can limit scopes when you request a patron’s token. That makes sense. But what do you do if you’re not requesting a token? If you only have the creator token?
Again, there is no patron’s access token. I am not requesting a token. No one is logging in or making a call.
So I can’t use http://localhost as the URI? A post earlier on this forum implied otherwise.
Let me try rephrasing this another way, since I am clearly mistaken in how this works.
On your portfolio site, you want to display the current amount of money you are making on Patreon, as well as the number of people supporting you.
How would you go about doing this?
You would need to use your creator access token to make a call to the api and get your campaign information. Within that result you can get information related to your campaign.
Okay, cool. Thank you. That’s what I thought. So how do I structure the URL to include my access token (ignoring security for the time being)?
Just check out PHP library, it has examples for common use cases.
In examples folder, obviously. However the readme also contains a quick authorization example.
All I was able to glean from that is that Patreon-PHP has a function that lets you make an api call. Specifically:
$api_client = new API($access_token);
I have dug into API.php and I still can’t figure out how to parse a URL together that includes the Access Token. It’s passed through the Authorization Header.
So is it impossible to have a single URL that I can drop into a browser that returns information? Does it have to go through a multi-step coded request? Because that’s all I’m getting from this.
There is an example down below in the readme of the library already?
It includes url construction to send users to login at Patreon. And receiving the info back.
If you want to make a call to the api with an access token you already have, you will need to send headers with the request. This would mean that you cant just copy/paste an url with an access token and get a result using normal browsers.If you can modify your browser to send custom headers while making the request, that is.
Okay, thank you thank you. That’s the information I needed. The other APIs I’ve noodled with let you put the access token in the Url and get the information from the browser. I was using that to make sure I had the right information before moving forward.
I’ll give XMLHttpRequest another shot then and see if I can get that to work.