1

I've registered as the Web app as required by the Reddit API for the Oauth access with identity, edit, flair, history, modconfig, modflair, modlog, modposts, modwiki, mysubreddits, privatemessages, read, report, save, submit, subscribe, vote, wikiedit, wikiread scopes.

I'd authorized my app and have exchanged the generated code for the access_token with 3600 seconds validity.

'use strict';

let request = require('request');
const USER_AGENT = 'web:com.example.server:v0.0.1 (by /u/sridharrajs)';
const token = '<my access_token within 3600 seconds validity>';

request({
  method: 'POST',
  url: 'https://www.reddit.com/api/vote',
  headers: {
    'User-Agent': USER_AGENT,
    'Authorization': `bearer ${token}`,
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  form: {
    id: "t1_9qy47p",
    dir: "1"
  },
  json: false
}, function (error, response, body) {
  if (error) {
    console.log('error', error);
  } else if (body.error) {
    console.log('body.error', body);
  }
  return console.log(body);
});

But when I try to upvote a reddit submission using API, I get an error.

{"message": "Forbidden", "error": 403}

The link that I'm trying to upvote is Tim Cook warns of ‘data-industrial complex’ in call for comprehensive US privacy laws

I tried switching both bearer and Bearer as per the answer in Reddit API returns HTTP 403, and tried using different User-Agent as suggested in 403 error when trying to get data from Reddit API. Nothing seem to work.

What am I missing?

Sridhar
  • 11,466
  • 5
  • 39
  • 43
  • You typically get a 403 forbidden back when you are hitting the endpoint incorrectly or you do not have all of the request data required to fulfill the request. If this were an auth issue most likely you would be receiving an unauthorized response. Are you using the request NPM package? Are you sure you are constructing the request properly, almost seems like you are missing the body of the request. – E McG Oct 25 '18 at 11:40
  • @EMcG yes. I'm using `request` npm. Also, I'm using form because of `'Content-Type': 'application/x-www-form-urlencoded'` header. Updated the question to reflect this – Sridhar Oct 25 '18 at 11:49

1 Answers1

3

Solved. I need to use https://oauth.reddit.com instead of www.reddit.com.

You may now make API requests to reddit's servers on behalf of that user, by including the following header in your HTTP requests:

Authorization: bearer TOKEN

API requests with a bearer token should be made to https://oauth.reddit.com, NOT www.reddit.com.

Community
  • 1
  • 1
Sridhar
  • 11,466
  • 5
  • 39
  • 43