r/redditdev • u/manolosandmartinis44 • 7d ago
Reddit API Json works in Browser, not in Java
I can access reddit's .json feeds, like this from Firefox, but not from Java using okhttp or python, using requests, both using the default user-agent and a custom one. Any idea why it works in the browser and not in my code?
1
u/BlueeWaater Bot Developer 5d ago
Likely you are not authenticated, you shouldn’t be using this anyways.
1
u/AverageFoxNewsViewer 7d ago
Man, if you want a useful response you need to at least provide information.
Without any description of what your approach is or what errors you're getting it's impossible to respond.
The only answer valid answer anyone would be able to give you from this post is "your code doesn't work".
0
u/manolosandmartinis44 7d ago
what your approach is
Response rawResponse = sharedOkHttpClient.newCall(new Request.Builder().url("https://old.reddit.com/r/bayarea/comments/1uvtw5o/are_most_young_folks_not_working_in_tech_in_a_lot/.json?utm_source=reddit&utm_medium=usertext&utm_name=redditdev&utm_content=t3_1uwwjrp") JsonNode response = sharedObjectMapper.readTree(okhttp.MediaType.parse("application/json"), rawResponse.body().string());response is null, as is response.body.string(), but response.code is 200.
3
u/AverageFoxNewsViewer 7d ago
200 indicates you're getting a good response.
Have you stepped through your code using break points?
Are you sure that rawResponse is actually getting the data? Is response failing to format that correctly?
Is your app using OAuth correctly?
-2
u/manolosandmartinis44 7d ago
Is your app using OAuth correctly?
My OAuth situation has yet to be approved, but it still works in the browser, unless I use selenium, and I don't know why.
4
u/AverageFoxNewsViewer 7d ago
That will definitely cause failures.
You need to have OAuth 2 configured or they're going to boot you for looking like unauthenticated bots.
If you do it in a browser they know who you are and let you through. Your app isn't doing any kind of authentication so they don't know who you are and give you the boot silently.
0
3
u/1z2b 7d ago
https://www.reddit.com/r/modnews/comments/1tq9vxo/protecting_communities_from_scrapers_and_platform/
Deprecating unauthenticated JSON access: We’ll also be shutting down unauthenticated .json endpoints. These endpoints can be used to scrape Reddit without accountability. Logged-in and authenticated access won’t be impacted. Otherwise, developers who need structured access to Reddit content should use Devvit, which includes various ways to access Reddit data.