Struggling with making /api/login/ function properly - using JavaScript and Reddit

Oh no, I've reached my limit of attempts... just received the message "you are doing that too much. try again in 27 minutes." So, I decided to come here and seek help.


Here is the request I am making

URL:

http://www.reddit.com/api/login/

Headers:

User-Agent: "Reddit test app"

POST DATA:

user=USERNAME&passwd=PASSWORD&api_type=json

I found that putting the parameters directly in the URL works strangely! However, I would prefer not to do this as it may pose a security risk to pass the password in the URL.

For example

http://www.reddit.com/api/login/?user=USERNAME&passwd=PASSWORD&api_type=json


Another query... how can I access /api/v1/me/ ?

I've tried passing modhash as both a GET/POST parameter and also by sending "uh" as a Header, but neither method seems to be working.


Any insights into what I might be doing incorrectly? Thank you! :)

Answer №1

To begin, consider using for authentication. This eliminates the need to include parameters in the URL.

Additionally, /api/v1/me/ requires OAuth2 access with the 'identity' scope and cannot be accessed through a logged-in session.

If you are having trouble with your POST request, it is possible that your data is not encoded correctly. Try sending your data via POST to to see if you receive the expected response.

Answer №2

While this question may be old, it's still important to provide an answer for anyone who may come across it in the future. The issue at hand seems to stem from the lack of utilizing the "content-type" in the header, causing the post data to not be processed correctly. By simply adding ".setRequestHeader("Content-type","application/x-www-form-urlencoded");", one can rectify this mistake. It's possible that many developers rely on frameworks like jQuery to handle this internally without realizing the need to specify it explicitly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am having trouble having a select component populate with new child components while still maintaining its original value

So here's the situation. Let me simplify things for you. I'm in the process of developing an app that generates JSON queries to be sent to a server. The query-building components are structured in a nested manner: QueryContainer > QueryGroup ...

Sending Code Through POST Using jQuery

Users can input code in a textarea with the id of 'code_box'. <textarea id = 'code_box'></textarea> The following jQuery uses ajax to send the code to a PHP script for processing. $('#submit_button').click(funct ...

Error: The function `map` cannot be applied to the components

My issue involves using the same components in two different locations, where one isn't functioning properly. The error is occurring in Board.js: TypeError: components.map is not a function const Board = () => { const [components, ...

The issue you're encountering in React Native Expo is a restriction where Hooks can only be invoked within the body of a function

I'm currently working on a mobile app with React Native expo, but I've encountered an issue: Invalid hook call. Hooks can only be called inside the body of a function component.... I have checked other solutions on Stack Overflow and verified th ...

Animation loading on React.js when the page or URL is changed

Just starting out with React and trying to incorporate a loading animation when the page/url changes on button click - check it out here: https://codesandbox.io/s/cthululel-7zmsl?fontsize=14 Successfully got the animation working on initial load, but runn ...

Creating a hierarchical JSON layout for constructing dual d3.js graphs side by side

I am currently struggling with navigating through a JSON structure that I created in order to generate side-by-side donut charts. I suspect that my structure is not ideal and would greatly appreciate any guidance. My inspiration comes from Mike Bostock&ap ...

Is there a way to ensure that a method is always called in JavaScript after JQuery has finished loading

We recently integrated jquery load into our website to dynamically load content into a div without refreshing the whole page. However, we've noticed that in the complete function, we have to constantly re-apply various bindings. Is there a way to set ...

Tips for automatically filling in fields when a button is clicked in a React application

I'm attempting to pre-fill the form fields that are duplicated with data from already filled fields. When I click the "Add Fields" button, new fields are replicated, but I want them to be pre-populated with data from existing fields. How can I access ...

Issue with AngularJS toggle being obstructed by Math operation

I am facing an issue with my table rows where cells are being filled with words from an API. I have implemented a feature that allows users to toggle the selection of a cell. To achieve this, I am using ng-class={selected:toggle} and ng-click="toggle = !to ...

The use of Buffer() is no longer recommended due to concerns regarding both security vulnerabilities and

I'm encountering an issue while trying to run a Discord bot. The code I'm using involves Buffer and it keeps generating errors specifically with this code snippet: const app = express(); app.get("/", (req,res) => { if((new Buffer(req.quer ...

Displaying content on a webpage using PHP, AJAX, and HTML

Looking to update my current form setup. I have a basic Form below: <form action="" method="POST"> <input type="button" value="Generate Numbers" onclick="on_callPhp1()"/> </form> Accompanied by this javascript code: <script type="te ...

Tips for retrieving a variable from a $.getJSON function

My question is similar to this one: How can I return a variable from a $.getJSON function I have come across several duplicates on Stack Overflow, but none of them provided a satisfactory answer. I understand that $.getJSON runs asynchronously, and I hav ...

Update the DOM elements following the completion of an AJAX load operation

Let me explain the issue I'm encountering: I begin with <container> <div id="foo"></div> </container> After that, I populate content into the container div using Ajax <container> <div id="bar"></div&g ...

Is it possible to modify CSS properties using Ajax?

I am attempting to dynamically change the background color of a div using AJAX to fetch the user's specified color from the database. Below is the code snippet I am using: $.ajax({type: "POST", data: {id: id}, url: "actions/css.php", success: functio ...

I would like to implement a delay on this button so that when it is clicked, there is a pause before navigating

When I add the delay, it doesn't work, and when I remove it, it does. What can I do to make this button have a href link that delays before redirecting to another page? (I'm a newbie) I need to click and wait 3 seconds before navigating to other ...

Images are not loading in NextJs image component on a Digital Ocean deployed application

I recently encountered an issue with my NextJs project. While using the NextJs Image Component for images, everything worked perfectly fine when running locally. However, after deploying the project on Digital Ocean, all the images served through the Next- ...

receiving a pair of components instead of just one

Here is the code for router.js: import React from 'react'; import { Route } from 'react-router-dom'; import CommentList from './containers/commentview'; import CommentDetalList from './containers/commentdetailview'; ...

Is there a way to identify when a specific DIV element changes its dimensions without continuously polling for updates? In other words, I am looking for a method to

Running ads on my website has been great, but one of the ads keeps changing the dimensions of the DIV it's in, causing layout issues with other elements on the page. To solve this problem, I need to add an event listener to the specific DIV element t ...

All file upload requests consistently result in a status code of 400

I am encountering an issue with file uploading in Express. Every time I send a request with multipart/form-data, I receive a 400 bad request response with no error message, just an empty object. Currently, I am using busboy-body-parser for parsing multipar ...

Guide to executing a server-side FUNCTION within a specific namespace room exclusively with the help of socket.io, express, and node.js

I've been developing an online multiplayer game using socket.io, express, and node.js. The server is supposed to detect the number of users connected to a specific room within a namespace and start the game if there are more than two players. However, ...