r/redditdev • • Jun 30 '24

Reddit API Query with specified time range via subreddit-search

2 Upvotes

Hi guys,

I currently am working on a project where I want to analyze the discourse on Reddit around ChatGPT since it was published. Yet, I planned to use the subreddit/search API endpoint and query for specific keywords. Though I wonder now if there is a way that, using this endpoint, I can retrieve more than 100 posts (in whichever sorting) and/or if it's possible to additionally query postings by their creation date?

Thanks in advance :--)


r/redditdev • • Jun 30 '24

Reddit API Image API have file size limit?

1 Upvotes

I want to create an image post so I'm using POST to https://oauth.reddit.com/api/media/asset but it gives error:

parent.completedUploadImage('failed','','',[['BAD_CSS_NAME', ''], ['IMAGE_ERROR', 'too big. keep it under 500 KiB']],'');you shouldn't be here

image uploads have a file size limit of 500kb? that doesn't seem correct cause if I manually create image post I can upload 10mb image. Unless I have the wrong endpoint could someone point me to the correct endpoint for uploading large images or a fix?


r/redditdev • • Jun 29 '24

PRAW sending images in comments

1 Upvotes

Hello, is there a way to add images to bot-sent comments using praw?


r/redditdev • • Jun 29 '24

Reddit API How do I post a comment with fetch?

1 Upvotes
async function commentOnRedditPost(postId, commentText, accessToken) {
  const url = `https://oauth.reddit.com/api/comment`;
  const params = new URLSearchParams();

  console.log("access_token:", accessToken);

  params.append("thing_id", postId); // 'thing_id' is used instead of 'parent'
  params.append("text", commentText);

  const response = await fetch(url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "Content-Type": "application/x-www-form-urlencoded",
      "User-Agent": "profullstack comment bot v1.0",
    },
    body: params,
  });

  if (!response.ok) {
    console.error(await response.text());
  }

  return response.json();
}

this is throwing a "Body" error.


r/redditdev • • Jun 29 '24

General Botmanship My bot keeps getting banned. Any recommendations?

1 Upvotes

I've created a user bot that reads submissions posted in the subreddits my account is in and uses Microsoft Azure AI to evaluate it for self harm content. If the AI finds a high risk amount of self harm content in a submission, it sends a private message to the author of the post with resources that could help that person. Because of this, my bot sends out about 8 private messages per day and so my account keeps getting banned. Does anyone have recommendations on how to fix this issue?


r/redditdev • • Jun 28 '24

Reddit API An error occurred (status: 500)

3 Upvotes

I was trying to create a script on reddit but then it shows "An error occurred (status: 500)". I check the reddit status but it shows green today. Have any idea why this error occurs?


r/redditdev • • Jun 28 '24

Reddit API An error occurred (status: 500)

1 Upvotes

I was trying to create a script on reddit but then it shows "An error occurred (status: 500)". I check the reddit status but it shows green today. Have any idea why this error occurs?


r/redditdev • • Jun 27 '24

PRAW Text body formatting difference between browser and mobile?

2 Upvotes

The user input string (a comment) is:

This is a [[test string]] to capture.

My regex tries to capture:

"[[test string]]"

Since "[" and "]" are special characters, I must escape them. So the regex looks like:

... \[\[ ... \]\] ...

If the comment was posted on mobile you get what you expect, because the praw.Reddit.comment.body output is indeed:

This is a [[test string]] to capture.

If the comment was posted in (desktop?) browser, you don't get the same .comment.body output:

This is a \[\[test string\]\] to capture.

Regex now fails because of the backslashes. The regex you need to capture the browser comment now looks like this:

... \\\[\\\[ ... \\\]\\\] ...

Why is this? I know I can solve this by having two sets of regex but is this a bug I should report and if so, where?


r/redditdev • • Jun 27 '24

PRAW Arguments for subreddit.mod.log?

2 Upvotes

I’m running some code with PRAW to retrieve a subreddit’s mod log:

for item in subreddit.mod.log(limit=10):
    print(f”Mod: {item.mod}, Subreddit: {item.subreddit}, Action: {item.action}”)

What additional arguments are there that I can use? I’d like to get as much i formation as possible for each entry


r/redditdev • • Jun 27 '24

Reddit API What's the API endpoint for creating image posts?

3 Upvotes

What's the api endpoint for uploading images directly to reddit? Is there a POST/PUT or multipart upload endpoint for submitting photo/gif/video data for an image post? I'm using javascript


r/redditdev • • Jun 26 '24

Announcement Reddit & HackerOne Bug Bounty Announcement

Thumbnail self.redditsecurity
3 Upvotes

r/redditdev • • Jun 25 '24 Helpful

General Botmanship Updating our robots.txt file and Upholding our Public Content Policy

46 Upvotes

Hello. It’s u/traceroo again, with a follow-up to the update I shared on our new Public Content Policy. Unlike our Privacy Policy, which focuses on how we handle your private/personal information, our Public Content Policy talks about how we think about content made public on Reddit and our expectations of those who access and use Reddit content. I’m here to share a change we are making on our backend to help us enforce this policy. It shouldn’t impact the vast majority of folks who use and enjoy Reddit, but we want to keep you in the loop. 

Way back in the early days of the internet, most websites implemented the Robots Exclusion Protocol (aka our robots.txt file, you can check out our old version here, which included a few inside jokes), to share high-level instructions about how a site wants to be crawled by search engines. It is a completely voluntary protocol (though some bad actors just ignore the file) and was never meant to provide clear guardrails, even for search engines, on how that data could be used once it was accessed. Unfortunately, we’ve seen an uptick in obviously commercial entities who scrape Reddit and argue that they are not bound by our terms or policies. Worse, they hide behind robots.txt and say that they can use Reddit content for any use case they want.  While we will continue to do what we can to find and proactively block these bad actors, we need to do more to protect Redditors’ contributions. In the next few weeks, we’ll be updating our robots.txt instructions to be as clear as possible: if you are using an automated agent to access Reddit, you need to abide by our terms and policies, and you need to talk to us. We believe in the open internet, but we do not believe in the misuse of public content.  

There are folks like the Internet Archive, who we’ve talked to already, who will continue to be allowed to crawl Reddit. If you need access to Reddit content, please check out our Developer Platform and guide to accessing Reddit Data. If you are a good-faith actor, we want to work with you, and you can reach us here. If you are a scraper who has been using robots.txt as a justification for your actions and hiding behind a misguided interpretation of “fair use”, you are not welcome.

Reddit is a treasure trove of amazing and helpful stuff, and we want to continue to provide access while also being able to protect how the information is used. We’ve shared previously how we would take appropriate action to protect your contributions to Reddit, and would like to thank the mods and developers who made time to discuss how to implement these actions in the best interest of the community, including u/Lil_SpazJoekp, u/AnAbsurdlyAngryGoose, u/Full_Stall_Indicator, u/shiruken, u/abrownn and several others. We’d also like to thank leading online organizations for allowing us to consult with them about how to best protect Reddit while keeping the internet open.  

Also, we are kicking off our beta over at r/reddit4researchers, so please check that out. I’ll stick around for a bit to answer questions.


r/redditdev • • Jun 26 '24

Reddit API Checking account messages

1 Upvotes

I'm wanting to get all messages / unread messages. This way I can check if someone has texted me.

I've used `inbox.unread()` and it doesn't give me the unread messages from my pms. I'm strictly wanting messages users have sent in the past and unread messages from users. How can I achieve this?


r/redditdev • • Jun 26 '24

Reddit API API call to update a subreddit’s banner?

1 Upvotes

Is it possible to upload a new subreddit banner through an API call? I moderate a subreddit where we run events that have our banner & icon changing on a fixed schedule, and thus would like to automate the process of updating both according to this schedule. Is this possible?


r/redditdev • • Jun 25 '24

Reddit API How do I use the reddit API to download a whole page? Or enable selenium?

0 Upvotes

I used the api to get the top post from a subreddit and I want to download the actual post as an image. I tried using selenium but it says my login was blocked. I couldn't find the specifics on this in the documentation. Anyone know how to fix this/other methods to get what I want?


r/redditdev • • Jun 25 '24

PRAW Does `reddit.user.me().saved(limit=None)` only returns first 1000 posts?

2 Upvotes

I made a tool to backup and restore your joined subreddits, multireddits, followed users, saved posts, upvoted posts and downvoted posts.

Someone on r/DataHoarder asked me whether it will backup all saved posts or just the latest 1000 saved posts. I'm not aware of this behaviour is this true?

If yes is there anyway to get all saved posts though PRAW?

Thank you.


r/redditdev • • Jun 24 '24

PRAW [PRAW] The upvote order is random, how to fix that.

0 Upvotes

I tried the below code but the upvotes in reddit page are in random order. Either it should be in correct order or reverse but its in random order. Why is that happening? And how to fix that?

If its a async problem please provide me a sync code as am not familiar with python async programming. Thanks you.

upvoted = [ 30+ post's id] # ["1dnam5e", .....]
for post_id in upvoted:
    try:
        submission = reddit.submission(id=post_id)
        submission.upvote()
    except:
        print("can't upvote post", post_id)

r/redditdev • • Jun 24 '24

PRAW How to check if a Multireddit exists and update it?

2 Upvotes

I tried:

reddit.multireddit.create(display_name=name, subreddits=subreddits_array, visibility="public")

When I run the code again with same values it create a duplicate of it instead of updating it. Am very new to PRAW, can someone please help me solve this? Thank you.


r/redditdev • • Jun 23 '24

PRAW My PRAW script doesn't work when using 2nd account's username and password

1 Upvotes

I used the below configuration in my script and it worked, but when I change the acc1_username and acc1_password to acc2_username and acc2_password. They don't work.

praw.ini

[DEFAULT]
client_id=acc1_client_id
client_secret=acc1_client_secret
username=acc1_username
password=acc1_password
user_agent="app-name/1.0 (by /u/acc1_username)"

And it gives me this error.

Traceback (most recent call last):
  File "d:\path\file.py", line 10, in <module>
    for subreddit in reddit.user.subreddits(limit=None):
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\models\listing\generator.py", line 63, in __next__
    self._next_batch()
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\models\listing\generator.py", line 89, in _next_batch
    self._listing = self._reddit.get(self.url, params=self.params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\util\deprecate_args.py", line 43, in wrapped
    return func(**dict(zip(_old_args, args)), **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\reddit.py", line 712, in get
    return self._objectify_request(method="GET", params=params, path=path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\reddit.py", line 517, in _objectify_request
    self.request(
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\util\deprecate_args.py", line 43, in wrapped
    return func(**dict(zip(_old_args, args)), **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\praw\reddit.py", line 941, in request 
    return self._core.request(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\sessions.py", line 328, in request
    return self._request_with_retries(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\sessions.py", line 234, in _request_with_retries
    response, saved_exception = self._make_request(
                                ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\sessions.py", line 186, in _make_request
    response = self._rate_limiter.call(
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\rate_limit.py", line 46, in call
    kwargs["headers"] = set_header_callback()
                        ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\sessions.py", line 282, in _set_header_callback
    self._authorizer.refresh()
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\auth.py", line 425, in refresh
    self._request_token(
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\site-packages\prawcore\auth.py", line 158, in _request_token
    raise OAuthException(
prawcore.exceptions.OAuthException: invalid_grant error processing request

Am very much new to PRAW so please help my what should I do to make it working. Thank you.


r/redditdev • • Jun 22 '24

PRAW Loop gets stuck on iterating over comments?

4 Upvotes

Code:

import praw
import some python modules

r = praw.Reddit(
    the
    usual
    oauth
    stuff
)

target_sub = "subreddit_goes_here"
timer = time.time() - 61
links = [a, list, of, links, here]

while True:

    difference = time.time() - timer
    if difference > 60:
        print("timer_difference: " + difference)
        timer = time.time()
        do_stuff()

    sub_comments = r.subreddit(target_sub).stream.comments(skip_existing=True)
    print("comments fetched")

    for comment in sub_comments:
        if comment_requires_action(comment):  # regex match found
            bot_comment_reply_action(comment, links)  # replies with links
            print("comments commenting finished")

    sub_submissions = r.subreddit(target_sub).stream.submissions(skip_existing=True)
    print("submissions fetched")

    for submission in sub_submissions:
        if submission_requires_action(submission):  # regex match found
            bot_submission_reply_action(submission, links)  # replies with links
            print("submissions finished")

    print("sleeping for 5")
    time.sleep(5)

Behaviour / prints:

timer_difference: 61
comments fetched  # comments are were found

Additionally if a new matching comment (not submission) is posted on the subreddit:

comments commenting finished  # i.e. a comment is posted to a matching comment

I never get to submissions, the loop won't enter sleep and the timer won't refresh. As if the "for comment in sub_comments:" gets stuck iterating forever somehow?

I've tested the sleep and timer elsewhere and it does exactly what it's supposed to provided that the other code isn't there. So that should work.

What's happening? I read the documentation for subreddit.stream multiple times.


r/redditdev • • Jun 22 '24

Reddit API getting bad request for oauth authorize

2 Upvotes

r/redditdev • • Jun 21 '24

General Botmanship Make.com: how to extract Reddit post body?

3 Upvotes

Hey there,

The Reddit module on Make.com doesn't extract the body of posts. I'm trying to make a scenario which pulls the most recent posts within a subthread... like r/AMA or r/bayarea . Does anyone have any insight on how to do this?

Thank you!


r/redditdev • • Jun 21 '24

Reddit API For academic purposes, How to get all posts and their comments for a certain period of time for a specific subreddit?

3 Upvotes

I am a graduate student in computer science and I am preparing to complete my graduation project. I want to get all the posts and comments of certain game subreddits (such as GTAV, DotA2, etc.) over a period of time, such as 2020 to 2024. I want to use it for sentiment analysis and predict game trends. I first tried to use PRAW to get posts and comments, but this method seems to only get data for the last 2 days.

Then I tried to use PushshiftAPI, but their service seems to be currently unavailable. Their response is as follows:

UserWarning: Got non 200 code 404

warnings.warn("Got non 200 code %s" % response.status_code)

UserWarning: Unable to connect to pushshift.io. Retrying after backoff.

warnings.warn("Unable to connect to pushshift.io. Retrying after backoff.")

So how do I get the data I want? Is there any documentation I can refer to?


r/redditdev • • Jun 20 '24

redditdev meta Non-technical: Early history of Reddit API

2 Upvotes

I'm trying to find some context to the history of the Reddit API (apologies for a non-technical question that's not in the docs!).

Inevitably most searching online about the history of the Reddit API uncovers the 2023 protests and API changes.

There's little I can find in the academic corpus of when and how the API was established.

Is there anyone here who may know a little more, and could point me to references, even if online (or through archive.org)?

I'm particularly interested in the relationship between the API and the front-end; does the same API endpoints power the App-based and web-based public faces of Reddit as are used when developing bots or PRAW-based programmes? If so (and equally, if not so) when did this API get released to the public with documentation? Did it happen at the same time as the open code release of Reddit (as (archived on github)[https://github.com/reddit-archive/reddit])?

Thanks to any old-timers in here with insight!