尝试使用Javascript从Reddit获取图像?

尝试使用Javascript从Reddit获取图像?,javascript,oauth,reddit,Javascript,Oauth,Reddit,对于这个特殊的任务,我决定最好使用RedditAPI。看着不同的包装器,我选择了使用。示例非常清楚,我想使用类似这样的方法来完成身份验证: const snoowrap = require('snoowrap'); const otherRequester = new snoowrap({ userAgent: 'put your user-agent string here', clientId: 'put your client id here', clientSe

对于这个特殊的任务,我决定最好使用RedditAPI。看着不同的包装器,我选择了使用。示例非常清楚,我想使用类似这样的方法来完成身份验证:

const snoowrap = require('snoowrap');

const otherRequester = new snoowrap({
    userAgent: 'put your user-agent string here',
    clientId: 'put your client id here',
    clientSecret: 'put your client secret here',
    username: 'put your username here',
    password: 'put your password here'
});
我可以在上找到重要信息,如clientID和clientSecret。让我困惑的是userAgent输入。我到底应该在这里输入什么


我想我可以转到由同一个用户创建的。然而,在流程结束时,我似乎收到了一个Reddit错误的请求

用户代理是发送请求的浏览器:

可以使用以下命令填充该数据:

navigator.userAgent

编辑:

上述方法仅适用于客户端,在服务器端,如果您在NodeJSPressJS环境中,则可以从执行API调用的函数的请求参数中的headers数据获取用户代理。大概是这样的:

app.get('/api-call', function(request, response){
    const snoowrap = require('snoowrap');

    const otherRequester = new snoowrap({
        userAgent: request.headers['user-agent'], 
        clientId: 'put your client id here',
        clientSecret: 'put your client secret here',
        username: 'put your username here',
        password: 'put your password here'
    });
    // rest of the code
});

对于userAgent,您需要在那里放置一个用户代理字符串。我的用户代理字符串到底是什么?在哪里可以找到它@SVENWRITESCODE我真的不是故意粗鲁,但是如果你用谷歌搜索我的用户代理字符串,第一个名为what's my user agent的网站是什么“用户代理和浏览器工具”会告诉您。@SvenWritesCode是的,我看过了,但这是我的机器特有的,我希望它能适用于所有机器。我似乎收到了错误:错误:找不到模块“navigator”。我应该在这里做什么?你是在客户端还是服务器端执行这个函数?在服务器端