代码之家  ›  专栏  ›  技术社区  ›  Sridhar An Nguyen

Reddit在通过API向上投票时给出403

  •  1
  • Sridhar An Nguyen  · 技术社区  · 7 年前

    Web app 按业主要求 Reddit API 对于Oauth访问 identity, edit, flair, history, modconfig, modflair, modlog, modposts, modwiki, mysubreddits, privatemessages, read, report, save, submit, subscribe, vote, wikiedit, wikiread 范围。

    我已经授权了我的应用程序,并将生成的代码交换给了 access_token 具有 3600 秒有效期。

    '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);
    });
    

    但当我试着 upvote a reddit submission using API ,我得到一个错误。

    我想说的是 Tim Cook warns of ‘data-industrial complex’ in call for comprehensive US privacy laws

    bearer Bearer 根据中的答案 Reddit API returns HTTP 403 ,并尝试使用不同的 User-Agent 403 error when trying to get data from Reddit API . 似乎什么都没用。

    我错过了什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Community Mohan Dere    6 年前

    解决了的。我需要使用 https://oauth.reddit.com 而不是 www.reddit.com.

    您现在可以代表该用户向reddit的服务器发出API请求,方法是在HTTP请求中包含以下标头:

    Authorization: bearer TOKEN
    

    带有承载令牌的API请求应发送到 https://oauth.reddit.com ,不是www.reddit.com.

    推荐文章