I wanted to integrate the newish award system that Reddit introduced about a year back that goes beyond just silver/gold/platinum and adds some cool new ones, for example this post has a ton of the new ones.
It's easy enough to display these awards through the post's JSON API, but awarding them or even viewing what awards are available doesn't seem very clear to me.
Through Chrome's Inspector I can see it accesses Reddit's GraphQL endpoint that they introduced about a year back, I don't see a "normal" version. In that thread Reddit admins seem to make it clear they don't mind people using the GraphQL endpoints but that they're fluctuating so if something breaks it's on you, which makes sense and is fine.
If I copy the curl
request to the GraphQL API endpoint for listing what the new awards available are, it essentially hits https://gql.reddit.com
and passes this JSON to format the request:
{
"id": "6dd9088f9a72",
"variables": {
"subredditId": "t5_2s3j5",
"includeAppreciation": true,
"includePremium": true
}
}
I can perform this curl really easily (I've removed the bearer token obviously, but it's the one from the official app or the website):
curl 'https://gql.reddit.com/?request_timestamp=1583344097996' -H 'authority: gql.reddit.com' -H 'x-reddaid: S7K4B47S5XT7AHYA' -H 'x-reddit-loid: 00000000000004mwol.2.1292784975541.Z0FBQUFBQmRuSmNma0ZpN3RWMXhzS2pHcnpaMzFoSXA1WXhLeEhPdlBiYUU5UkRpQm9tRnNYSUQ2bVNuaWhZWUdZdFdsbVBjbjFnN3ltd2Nsb05DVGRsY0RzaGVkSXl2MjFfRS1HUUpDT1FTZ0FHS0o1SWd4bHhKMEJBb19GUjM5Y2xqYkR4QUhseU8' -H 'authorization: Bearer BEARER_TOKEN_HERE' -H 'content-type: application/json' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36' -H 'sec-fetch-dest: empty' -H 'x-reddit-session: HFtkmepq7kRhJpbFfo.0.1583344088148.Z0FBQUFBQmVYLW5ZV1JOUng4Vno2dGEtU1RjX0V6R29wYnhWdC1PeF9HQzVxdTBvMHhXZnBITmdXZ3F3aUJtbzc4Z25GTjVpVlhpa09HUUp1Wm1GeHpqdnQyZ29PYzFzeG8talVqTDNHdDZQTjY5YnFmWlpCdTA3SVRsT1VRLWtGV0F4SzhDNHhINXE' -H 'accept: */*' -H 'origin: https://www.reddit.com' -H 'sec-fetch-site: same-site' -H 'sec-fetch-mode: cors' -H 'referer: https://www.reddit.com/' -H 'accept-language: en-US,en;q=0.9' --data-binary '{"id":"6dd9088f9a72","variables":{"subredditId":"t5_2r77k","includeAppreciation":true,"includePremium":true}}'
And I get back the following correct JSON listing the available rewards: https://gist.github.com/christianselig/2c407329cd84d4dbe5c88fb181c37845
However as soon as I change the Reddit-supplied bearer token to the one from my app (that I've verified is not expired) I get a 403 Forbidden error.
Is the GraphQL API just blocked for anyone not Reddit? If so does anyone know how to get a list of the available new rewards and how to award them? I'd find it weird if Reddit wasn't making such a feature available given that A) it's one of the few ways that they make money, so having third party apps integrate it would be valuable B) you can already view them, I just want to gift them too with the available coins on my accounts (like the old API).
EDIT
After closer inspection it actually seems possible to give out the new awards via the old API /api/v2/gold/gild
provided you know the ID of the new item (eg: provide award_f44611f1-b89e-46dc-97fe-892280b13b82
for the "Helpful" award). That's a big stickler though, because there's no way to know the IDs/fetch them ahead of time that I've been able to discover.
I could hardcode the above JSON response into the app, but that would be fragile and not include community awards as there's an endless, changing amount.
Is there a way to expose the list of available awards for a specific post beyond just the GraphQL API? I'm assuming new API functionality has only been added via the new GraphQL endpoint if that's what internally Reddit is moving toward, and I understand not being able to make the GraphQL API public quite yet, but would it be possible to just expose this one endpoint publicly via the old REST API as well so we can use it in the mean time? Through my app several thousand dollars worth of Reddit Silver/Gold/Platinum have been given out, so I think it'd be a very great move for Reddit too to make this little one public.
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/redditdev/c...